C# and ADO.NET problem - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

C# and ADO.NET problem

AzraelROAzraelRO Posts: 1Member
what wrong with this code ?


private void button4_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection( "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\database.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
try
{
conn.Open();

SqlCommand cmd = new SqlCommand("UPDATE Tabel SET @var = @var1 WHERE Nume = '" + comboBox1.Text + "'");

SqlParameter param = new SqlParameter();
param.ParameterName = "@var";
param.Value = comboBox2.Text;
SqlParameter param1 = new SqlParameter();
param1.ParameterName = "@var1";
param1.Value = textBox9.Text;

cmd.Parameters.Add(param);
cmd.Parameters.Add(param1);

cmd.Connection = conn;

cmd.ExecuteNonQuery();
}
finally
{
if (conn != null)
{
conn.Close();
}
}
}

if i change @var in the updatestring with the actual name of the column it works ... but i need it like that

Please help
Sign In or Register to comment.