I'm trying to pull data from a bunch of text boxes and then insert them into a database and all is well except for two, one is that if they are null they error but that's not the concern right now.
When I have a textbox that is supposed to take a number it says it cannot convert varchar to float. The inserts work if I do them directly in SQL Server though (using SQL Server 2008) so I know that it's something in the code.
My textbox is just a simple:
<asp:TextBox id="CID" runat="server"></asp:TextBox>
And the code I have for pulling the information from the textbox is:
float custID = float.Parse(CID.Text);
I'm new to C# so if you could help me simply put that would be better but any help works. thx
Edit: this is the line the error I get:
Line 63:
Line 64: sqlConnection1.Open();
Line 65: cmd.ExecuteNonQuery();
Line 66: sqlConnection1.Close();
Line 67: }
Code requested:
cmd.CommandText = "INSERT INTO Customer VALUES('@custID', @mastName, @custName, @addrLn1, @addrLn2, @cCity, @cState, @cZip, @cZip4, @cCountry, @cusSince, @renewalDate, @cNotes, @salesRep, @conMem, @ilsProd, @numbSites, @guardItEsc)";
cmd.CommandType = CommandType.Text;
cmd.Connection = sqlConnection1;
Parsed w/ parameter:
float custID = float.Parse(CID.Text);
cmd.Parameters.AddWithValue("@custId", custID);
cmdand executes the query (since that's where the actual error is).