C# 无效的列名";ctn“;
我收到一个错误“无效列名”ctn“”…但我在数据类型为VarChar(100)的数据库中将我的列命名为“ctn”…txtcn文本框存储来自用户的值。请帮助我找出代码中的错误C# 无效的列名";ctn“;,c#,asp.net,C#,Asp.net,我收到一个错误“无效列名”ctn“”…但我在数据类型为VarChar(100)的数据库中将我的列命名为“ctn”…txtcn文本框存储来自用户的值。请帮助我找出代码中的错误 SqlConnection con = new SqlConnection(Properties.Settings.Default.cn); con.Open(); SqlCommand cmd = new SqlCommand("insert into tbbill (invoice, date, ctn, total,
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();
在Sql Server中运行查询并检查它是否仍然返回错误
然后使用
using
关键字自动处理对象,或者使用try catch
并在finally
块中处理对象。在Sql Server中运行查询并检查它是否仍返回错误
并使用
using
关键字自动处理对象,或使用try catch
并在finally
块中处理对象。显示tbbill的CREATE TABLE语句。请注意,如果上面的查询引发异常,您将无法处理cmd。将using
关键字与IDisposable对象一起使用。@AymanBarhoum OP只是突出显示错误。请尝试调试组成的查询,并直接在sql server中运行它。看看它是否有效或有效error@user3526313为什么不使用参数化查询?显示tbbill的CREATE TABLE语句。请注意,如果上面的查询引发异常,您将无法处理cmd。将using
关键字与IDisposable对象一起使用。@AymanBarhoum OP只是突出显示错误。请尝试调试组成的查询,并直接在sql server中运行它。看看它是否有效或有效error@user3526313为什么不使用参数化查询?这不是答案。问题应该作为评论发布。这不是答案。问题应作为评论发布。