I am inserting some values into SQL Server using C# code. I have created my RemainingPayment column in the database as Decimal(18,2) datatype and also allowed null. But when I execute my query from C#, it complains about:
Incorrect syntax near ,
It's important to note that I get that error only for the RemainingPayment column that has Decimal(18,2) data type. For another column that has nvarchar datatype, it's working fine.
Here is my code:
try
{
using (SqlConnection con = new SqlConnection(ConStr))
{
string query = "INSERT INTO tblExpEntry(RemainingPayment, CHQNo, TransactionID) VALUES (" + tbRemainingPayment.Text + ", '"+tbCHQNo.Text+"', '"+lbl_ID.Text+"')";
using (SqlCommand cmd = new SqlCommand(query,con))
{
cmd.CommandType = CommandType.Text;
con.Open();
cmd.ExecuteNonQuery();
MessageBox.Show("Transaction Successful.", "Created");
generateTransactionID();
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}