Click here to Skip to main content
15,909,466 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
SQL
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

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

For example :

C#
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
 
Share this answer
 
v2
Comments
Abhinav S 14-Apr-12 3:18am    
Very good advice.
phil.o 14-Apr-12 5:39am    
Thanks :)
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.
 
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