[英]Sql C# Invalid column name
private void button4_Click_1(object sender, EventArgs e)
{
string s = textBox1.Text;
SqlCeConnection conn = new SqlCeConnection(@"Data Source=D:\Desktop\DB2\DB2\Database1.sdf");
try
{
conn.Open();
SqlCeCommand cmd = new SqlCeCommand(" update Kambariai set Kliento ID = Kliento ID + s Where Kliento ID = 0 ", conn);
cmd.ExecuteNonQuery();
toolStripStatusLabel1.Text = "Duomenys įrašyti";
conn.Close();
}
catch (Exception ee)
{
MessageBox.Show(ee.Message);
}
}
Datatable schema shows that column exists but I still get error that Column name invalid maybe I forgot to write something please help me :) What I am trying to do is take text from textbox1.Text and update it datatable values where coulmn name is Kliento ID and value is 0. 数据架构显示该列存在,但我仍然得到列名无效的错误,也许我忘了写一些东西请帮助我:)我想要做的是从textbox1.Text获取文本并更新数据表值,其中coulmn名称是Kliento ID和值为0。
http://i.stack.imgur.com/ZM4LN.jpg http://i.stack.imgur.com/ZM4LN.jpg
For MySQL: (since the original question tagged mysql
) 对于MySQL :(因为原始问题标记为
mysql
)
Use backticks(`) around the field name. 在字段名称周围使用反引号(`)。
Try this way: SqlCeCommand cmd = new SqlCeCommand(" update Kambariai set Kliento ID
= Kliento ID
+ "+s+" Where Kliento ID
= 0 ", conn); 试试这种方式:SqlCeCommand cmd = new SqlCeCommand(“更新
Kliento ID
设置Kliento ID
= Kliento ID
+”+ s +“其中Kliento ID
= 0”,conn);
Side note: Back ticks are to be used for table and column identifiers, but are only necessary when the identifier is a MySQL reserved keyword, or when the identifier contains whitespace characters or characters beyond a limited set it is often recommended to avoid using reserved keywords as column or table identifiers when possible, avoiding the quoting issue.
附注:后面的刻度将用于表和列标识符,但仅当标识符是MySQL保留关键字时才需要,或者当标识符包含空格字符或超出有限集的字符时,通常建议避免使用保留关键字尽可能作为列或表标识符,避免引用问题。
Back ticks are necessary for situations like the following: 对于以下情况,后退滴答是必要的:
SELECT id, `my name`, `another field` , `field,with,comma`
For SQL Server: (since the image shows sql server
) 对于SQL Server :(因为图像显示
sql server
)
Try []
instead: 请尝试
[]
:
SqlCeCommand cmd = new SqlCeCommand(" update Kambariai set [Kliento ID] = [Kliento ID] + "+s+" Where [Kliento ID] = 0 ", conn);
尝试这个:
SqlCeCommand cmd = new SqlCeCommand("update Kambariai set [Kliento ID] = [Kliento ID] + " + s + " Where [Kliento ID] = 0", conn);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.