Skip to content Skip to sidebar Skip to footer

C# Sql Column Name Is Not Valid

private void button4_Click_1(object sender, EventArgs e) { string s = textBox1.Text; string s1 = comboBox1.Text; string s2 = comboBox2.Text; Sq

Solution 1:

Try this:

SqlCeCommandcmd=newSqlCeCommand("update Kambariai set Klientas="+s+"  Where [Kambario rūšis]='"+s1+"' ", conn);

Analysis:

From what you have tried, cmd has value like :

update Kambariai set Klientas=s Where [Kambario rūšis]=s1

From by putting proper double and single quotes around it, the value would be like:

update Kambariai set Klientas=1Where [Kambario rūšis]='bar'

Side Note:

I would not recommend this method since it increases the risk of SQL injection. Use parameterized query instead.

Solution 2:

Try This :

SqlCeCommandcmd=newSqlCeCommand(" update Kambariai set Klientas='" + s +"'  Where [Kambario rūšis]='" + s1 + "'", conn);

Post a Comment for "C# Sql Column Name Is Not Valid"