Click here to Skip to main content
15,885,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi!!!
i have a problem.. i am using viaual studio 2010 and i can insert data but i can't UPDATE & DELETE. The visual studio says this error: Incorrect syntax near 'Index'. If this is intended as a part of a table hint, A WITH keyword and parenthesis are now required. This is the code that i am using for the UPDATE command:
C#
da.UpdateCommand = new SqlCommand("UPDATE Studenti SET  ime = @ime, prezime = @prezime WHERE Index = @Index",cs);
            da.UpdateCommand.Parameters.Add("@ime", SqlDbType.VarChar).Value = txtVnesiIme.Text;
            da.UpdateCommand.Parameters.Add("@prezime", SqlDbType.VarChar).Value = txtVnesiPrezime.Text;
            da.UpdateCommand.Parameters.Add("@Index", SqlDbType.Int).Value = ds.Tables[0].Rows[studentiBS.Position][0];
            cs.Open();
            da.UpdateCommand.ExecuteNonQuery();
           cs.Close();

i have searched on the net but i cant find the answer. please help
Posted
Updated 10-May-10 5:21am
v2

1 solution

zareppmk wrote:
da.UpdateCommand.Parameters.Add("@Index", SqlDbType.Int).Value = ds.Tables[0].Rows[studentiBS.Position][0];

Error lies here.
You are tring to assign an object to int type parameter.

Try:
C#
da.UpdateCommand.Parameters.Add("@Index", SqlDbType.Int).Value = Convert.ToInt32(ds.Tables[0].Rows[studentiBS.Position][0].ToString());
 
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