Y
Yogita Negi
Guest
I want to insert data values in an access database on click of a button from a website of visual c# 2005.I used following code but it didnt work.Please tell me what is the error in this code.
protected void Button3_Click(object sender, EventArgs e)
{
string ds = "Data Source=.\\Microsoft Access Database File;AttachDbFilename=C:\\Documents and Settings\\neeraj\\My Documents\\Database1.mdb;Integrated Security=True;User Instance=True";
string comm = "INSERT INTO Table1 (first name,last name,gender) " + "VALUES(" + TextBox2.Text + ", " + TextBox1.Text + ",, " + TextBox3.Text + ");";
SqlConnection conn = new SqlConnection(ds);
SqlCommand myCommand = new SqlCommand(comm,conn);
try
{
conn.Open();
myCommand.ExecuteNonQuery();
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex);
}
finally
{
conn.Close();
}
}
Continue reading...
protected void Button3_Click(object sender, EventArgs e)
{
string ds = "Data Source=.\\Microsoft Access Database File;AttachDbFilename=C:\\Documents and Settings\\neeraj\\My Documents\\Database1.mdb;Integrated Security=True;User Instance=True";
string comm = "INSERT INTO Table1 (first name,last name,gender) " + "VALUES(" + TextBox2.Text + ", " + TextBox1.Text + ",, " + TextBox3.Text + ");";
SqlConnection conn = new SqlConnection(ds);
SqlCommand myCommand = new SqlCommand(comm,conn);
try
{
conn.Open();
myCommand.ExecuteNonQuery();
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex);
}
finally
{
conn.Close();
}
}
Continue reading...