无效的列名"ctn"

本文关键字:quot ctn 无效 | 更新日期: 2023-09-27 18:15:55

我得到一个错误"无效的列名"ctn"…但是我把我的列命名为"ctn"在数据库的数据类型VarChar(100)..TXTCN文本框存储来自用户的值。请帮我找出我的代码中的错误…

SqlConnection con = new SqlConnection(Properties.Settings.Default.cn);
con.Open();
SqlCommand cmd = new SqlCommand("insert into tbbill (invoice, date, ctn, total, tax, grandtotal) values('"+Convert.ToInt32(txtinvoice.Text)+"','"+Convert.ToDateTime(dateTimePicker1.Text)+"','"+txtcn.Text+"','"+Convert.ToSingle(txtttl.Text)+"','"+Convert.ToInt32(cmtax.SelectedValue)+"','"+Convert.ToSingle(txtgrdttl.Text)+"')", con);
cmd.CommandType = CommandType.Text; 
cmd.ExecuteNonQuery();//here i am getting error....
cmd.Dispose();

无效的列名"ctn"

在Sql Server中运行查询并检查是否仍然返回错误。

使用using关键字自动处置对象或使用try catch关键字在finally块中处置对象。