Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to insert some value at the specific field.

C#
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();



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.......
Posted
Updated 25-Apr-12 23:46pm
v3

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

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
C#
string.Format
helps to reduce errors while working with strings.

I hope it helps,
Cheers
 
Share this answer
 
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.
SQL
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900