Update SQL Table Thro C#
How would I update a SQL table through C#? I know in VBA I could use ADO, and I may be able to do the same in C#, but I don't know what references to add etc if that is the case. Can someone provide an example of how to do this?
Gopal MahadakPosted Feb 10, 2013, 4:54 AM
public OleDbConnection cn = new OleDbConnection(@"provider= sqloledb; Data Source=nameofserver\SQLEXPRESS;Initial Catalog=DataBase;Persist Security Info=True;User ID=userid;Password=pwd");
on buttonclick-----------
cn.Open();
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = cn;
cmd.CommandText = "update diarydata set SrNo=?Diary=?,CreatedDate=? where SrNo="+txtSrNo.Text+"";
cmd.Parameters.Add("@SrNo", OleDbType.Numeric).Value = int.Parse(textBox1).Text;
cmd.Parameters.Add("@DiaryData", OleDbType.VarChar).Value = richTextBox1.Text;
cmd.Parameters.Add("@CeratedDate", OleDbType.Date).Value = dateTimePicker1.Value;
cmd.ExecuteReader();
MessageBox.Show("Data updated");
cn.Close();