Click here to Skip to main content
15,913,055 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to get data from selected cells and insert into sql table
SQL
SqlCommand cmd = new SqlCommand("set identity_insert posudbe on INSERT INTO Posudbe (datumPosudbe,idClana,idNaslova) VALUES (@datumPosudbe,@idClana,@idNaslova) set identity_insert posudbe off", conn);
       cmd.Parameters.Add("@idClana", SqlDbType.Int).Value = gvClanovi.SelectedRow.Cells[0].Text;


Get this error:
C#
Failed to convert parameter value from a String to a Int32
Posted

Resolved using this: SelectedDataKey.Value.ToString()

It's working!

SQL
cmd.Parameters.Add("@idClana", SqlDbType.Int).Value = gvClanovi.SelectedDataKey.Value.ToString();
 
Share this answer
 
Try:
C#
cmd.Parameters.Add("@idClana", SqlDbType.Int).Value = int.Parse(gvClanovi.SelectedRow.Cells[0].Text);
 
Share this answer
 
Your string contains characters other than an Integer thats why your getting that error. Make sure that the parameter is Integer friendly.
 
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