Click here to Skip to main content
14,301,895 members
Rate this:
Please Sign up or sign in to vote.
SQLNew = "INSERT INTO wbtrans VALUES ('" & lblRecID.Text & "','" & 
         cboTermCode2.Text & "','" & cboWeiCode2.Text & "','" & 
         txtVehNum.Text & "'," & _
         "'" & txtDate2.Text & "','" & UpdTime & "','" & txtChitNum.Text & 
         "','" & WgType & "','" & WGStat & "',''," & _
         "'" & txtTare.Text & "','" & txtGross.Text & "','" & txtNet.Text & 
         "','','','','','','','','','','','',''," & _
         "'" & WgCharge & "','" & PayType & "','" & txtDebtCode.Text & "','" & 
         lblDebtName.Text & "',''," & _
         "'" & GetAppUser & "', '" & CDate(UpdDate) & "'," & _
         "'" & UpdTime & "','" & GetAppUser & "'," & _
         "'" & CDate(UpdDate) & "','" & UpdTime & "')"
Posted
Updated 13-Apr-12 2:47am
v4
Comments
swapnilKumbhar 13-Apr-12 5:13am
   
Check Every value with your DataBase Columns Data type.Use Debugging for checking values.
And use NULL for empty column(if allows).
Nelek 13-Apr-12 5:18am
   
added tags
Rate this:
Please Sign up or sign in to vote.

Solution 1

Don't build your SQL query like you do ; better create a SqlCommand object, and add SqlParameters to it.

For example :

string commandText = "INSERT INTO wbtrans VALUES(@recId, @termCode2)"

using (SqlConnexion cnx = new SqlConnection(connectionString))
using (SqlCommand cmd = new SqlCommand(commandText, cnx))
{
   cnx.Open();
   cmd.Parameters.AddWithValue("@recId", int.Parse(lblRecID.Text));
   cmd.Parameters.AddWithValue("@termCode2", cboTermCode2.Text);
   int result = cmd.ExecuteNonQuery();
}


I didn't put all the fields, but the scheme is the same.
I assumed recId id an integer, and termCode2 is a string. You have to pass the correct field type when you assign your parameters values.

Edited: forgot to open the connection
   
v2
Comments
Abhinav S 14-Apr-12 3:18am
   
Very good advice.
phil.o 14-Apr-12 5:39am
   
Thanks :)
Rate this:
Please Sign up or sign in to vote.

Solution 2

As the error suggests, one of the values that you are passing into the sql is not of a valid type e.g. you may be passing in string for a number type datafield in the database.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100