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

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.