Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 9th, 2012  |  syntax: None  |  size: 1.00 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. In c#.net.im getting invalid column name error but i have given a correct column name,how can i rectify this error [closed]
  2. private void button1_Click(object sender, EventArgs e)
  3.  {
  4.       SqlConnection conn = new SqlConnection("Data Source=INBLR-RK\SQLEXPRESS;Initial Catalog=dbo.EMployee;Integrated Security=True");
  5.       conn.Open();
  6.       SqlDataAdapter da = new SqlDataAdapter("INSERT INTO empnew Values (" + textBox1.Text + ", '" + textBox2.Text + "', '" + textBox3.Text + "','" + textBox4.Text + "'," + textBox5.Text + ",'" + textBox6.Text + "','" + textBox7.Text + "','" + dateTimePicker1.Text + "','" + textBox8.Text + "'," + textBox9.Text + ")", conn);
  7.       DataSet ds = new DataSet("empnew");
  8.       da.Fill(ds);
  9.       conn.Close();
  10.   }
  11.        
  12. using(SqlConnection  connection = new SqlConnection("ConnString"))
  13. {
  14.    connection.Open();
  15.    SqlCommand comm = new SqlCommand("insert into table_name(col_name) values (@value)",connection);
  16.    comm.Parameters.AddWithValue("@value",theValue);
  17.    comm.ExecuteNonQuery();
  18. }