在特定字段插入查询 [英] insert query at specific field

查看:78
本文介绍了在特定字段插入查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在特定字段中插入一些值.

i want to insert some value at the specific field.

string[] split = xx.Split(',');
                        intArray = new int[split.Length];
                        for (int i = 0; i < split.Length; i++)
                        {
                            intArray[i] = System.Convert.ToInt32(split[i]);

                        }

                        int x = 1;
                        string xxxx1 = "insert into document(bit_indicator) values("+x+") where id in(";
                        for (int k = 0; k < intArray.Length; k++)
                        {
                            xx += intArray[k] + ",";
                        }
                        xx = xx.Substring(0, xx.Length - 1) + ") and category='" + drop_cat.SelectedItem.Value + "' and subctgry='" + drop_sub_cat.SelectedItem.Value + "'";

                        SqlCommand cmd1 = new SqlCommand(xxxx1, c.getcon());
                        cmd1.ExecuteNonQuery();




它显示如下错误:靠近where子句的错误

在此先感谢


但是我想在特定字段插入值1,以便我将使用哪个查询.......




it display error like: error nearer to where clause

Thanks in advance


but i want to insert value 1 at specific field so which query i will user.......

推荐答案

hi,
为了找到错误,使用以下代码在行上插入一个断点:

In order to find the error insert a breakpoint on the line with this code:
SqlCommand cmd1 = new SqlCommand(xxxx1, c.getcon());


找出xxxx1中的确切内容,以帮助您发现问题.
其次,尝试使用string.Format创建一个Sql查询,以使您的工作更轻松.使用


to figure at what is exactly in xxxx1, in order to help you find the problem.
Secondly, try to use string.Format to create a Sql query to make your work easier. Using

string.Format

有助于减少使用字符串时的错误.

希望对您有帮助,
欢呼声

helps to reduce errors while working with strings.

I hope it helps,
Cheers


您正在尝试在此处组合select语句和insert语句.这就是为什么它抱怨.虽然可以执行此操作,但是格式必须非常具体,例如
You are trying to combine a select statement and insert statement here. That''s why it''s complaining. While you can do this, the format needs to be very specific, e.g.
INSERT INTO MyTable(Column1)
SELECT MyColumn
FROM MyOtherTable
WHERE ID=@ID

现在,您的语句看起来不应该执行这种类型的逻辑-因为您的选择标准是什么与放入列中的值无关.

Now, your statement doesn''t look like it should be doing this type of logic - as what would be your selection criteria has no bearing on the values being put into the column.


这篇关于在特定字段插入查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆