Hie people
I have a database named person that has a table called emp and a field by the name Names.Iam using VS 2005 how do I insert,delete and update the database.
this is my code-
I have a database named person that has a table called emp and a field by the name Names.Iam using VS 2005 how do I insert,delete and update the database.
this is my code-
Code:
private void button1_Click(object sender, EventArgs e)
{
string connetionstring = null;
string sql = null;
OleDbConnection cnn;
OleDbCommand cmd;
connetionstring = "Provider=Microsoft.Jet.Oledb.4.0; Data source=person.mdb;";
sql = "insert into emp values(' + textBox1.Text ')";
cnn = new OleDbConnection(connetionstring);
cmd = new OleDbCommand(sql);
cmd.Connection = cnn;
cnn.Open();
try
{
cmd.ExecuteNonQuery();
MessageBox.Show("record inserted");
}
catch(Exception ex)
{
MessageBox.Show("Can not open connection"+ex.ToString());
}
cnn.Close();
}
Comment