My name is Vinh Huynh, and I have a problem when I try to INSERT a record to a databse (SQL Server Express 05 edition)
A) Here is an ERROR MESSAGE shows on line 2 and line 4 below:
“FAILED to convert parameter value from a string to Int32”
-
comm.Parameters.Add(“@StationNumber”, System.Data.SqlDbType.Int)
-
comm.Parameters(“@StationNumber”).Value = stationTextBox.Text
-
comm.Parameters.Add(“@CategoryID”, System.Data.SqlDbType.Int)
-
comm.Parameters(“@CategoryID”).Value = categoryList.SelectedItem.Value
B) If I try to assign “stationTextBox.Text = an integer”, it WORKS great
For example, they are working with "an integer and Integer.Parse cast"
comm.Parameters("@StationNumber").Value = 45 or
comm.Parameters("@StationNumber").Value = Integer.Parse(stationTextBox.Text)
C) I have a PROBLEM with line 4 like this:
comm.Parameters("@CategoryID).Value = categoryList.SelectedItem.Value
Wow, I can NOT use Integer.Parse or Int32(“string”) cast, Please tell me why?
Otherwise, if we assigned to an integer, it work. WE don’t want to hard-code:
comm.Parameters("@CategoryID).Value = 2
Anyone out there with any suggestions or comments are welcome. Thank you so much for your valueable time. Have a nice day!!
Vinh…