Database & SQL

Moderators: None (Apply to moderate this forum)
Number of threads: 1194
Number of posts: 2247

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
C# and ADO.NET problem Posted by AzraelRO on 15 May 2009 at 9:59 AM
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



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.