I have an ASP.Net form, where it grabs a value from a textbox:
<asp:TextBox ID="txtID" runat="server" maxlength=9></asp:TextBox>
The ID HAS to be 9 numbers.
After it grabs it, I want to insert it into a database (SQL Server 2005), so I build a parameterized string,
'The Query
cmd.CommandText = "insert into table (aid) values ('@aid')"
cmd.Connection = conn
'Grab the value
cmd.Parameters.add("@aid", SqlDBType.Int).value = txtID.text
'Execute!
cmd.Connection.Open()
cmd.ExecuteNonQuery
However, it doesn't let me. It keeps giving the following error message:
Conversion failed when converting the varchar value '@aid' to data type int.
So I've tried a variety of things:
cmd.Parameters.add("@aid", SqlDBType.Int).value = 999999999
cmd.Parameters.add("@aid", SqlDBType.Int).value = Convert.ToInt16(txtID.text)
cmd.Parameters.add("@aid", SqlDBType.Int).value = Convert.ToInt32(txtID.text)
cmd.Parameters.add("@aid", SqlDBType.Int).value = Convert.ToInt64(txtID.text)
Nothing works. Inside the database, the type is "int".
Any ideas?