I have a question about C#. I wrote a function using ASP.net, when the user clicks the button, it should call this function and insert the sql to the local database. However, I don't know why it is not working. Can anyone help me?
My local database is Access, which is stored under the 'App_Data' folder.
protected void button1_Click(object sender, EventArgs e)
{
SqlConnection myConnection = new SqlConnection(connectionString);
// I think the problem is here, but I don't know how to do
SqlCommand myCommand = new SqlCommand("INSERT INTO [car] ([carName], [carType]) VALUES (@carName, @carType)", myConnection);
SqlParameter carName= myCommand.Parameters.Add("@carName", SqlDbType.Text);
SqlParameter carType= myCommand.Parameters.Add("@carType", SqlDbType.Text);
carName.Value = carNametb.Text;
carType.Value = carTypetb.Text;
myConnection.Open();
myCommand.ExecuteNonQuery();
// need to close() the connection where?
}