ASP.NET: How to Insert record into MS Access Data from ASP.NET

Resources:

protected void btnAdd_Click(object sender, EventArgs e)
{
string adminNumber = txtAdminNumber.Text.ToString();
string surname = txtSurname.Text.ToString();
string forname = txtForname.Text.ToString();
//Boolean induction = true;
Boolean induction = Convert.ToBoolean(ddlInduction.SelectedItem.Value.ToString());
string called = “called”;
string conString = @”Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\inetpub\wwwroot\GYMREG\App_Data\GymReg.accdb”;
OleDbConnection conn = new OleDbConnection(conString);
string sql = “Insert into dbo_vwStudCYAll(AdmissionNumber, Surname, Forename, Called, Induction) values(?,?,?,?,?)”;

OleDbCommand comm = new OleDbCommand(sql, conn);
comm.CommandType = CommandType.Text;
comm.Parameters.AddWithValue(“AdmisssionNumber”, adminNumber);
comm.Parameters.AddWithValue(“Surname”, surname);
comm.Parameters.AddWithValue(“Forename”, forname);
comm.Parameters.AddWithValue(“Called”, called);
comm.Parameters.AddWithValue(“Induction”, induction);

conn.Open();
try
{
comm.ExecuteNonQuery();
}
catch(Exception ex)
{
throw ex;
}
finally
{
conn.Close();
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s