D
DC
My update code seems to execute without error but doesnt write the data
back to my database, am I leaving someting out? Do I need to tell the
DataAdapter to update the database somewhere?
private void btnUpdateSeminar_Click(object sender, System.EventArgs e)
{
string strConnectionString;
strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source='C:\\Program Files\\Common Files\\ODBC\\Data
Sources\\seminars.mdb';";
string UpdateSemSql = "UPDATE SeminarList SET Speaker = '" +
tbSpeaker.Text + "', SpeakerEmail = '" + tbSpeakerEmail.Text +
"', SpeakerInstitution = '" + tbSpeakerInstitution.Text +
"',SeminarTitle = '" + tbSeminarTitle.Text + "', SeminarDate = #" +
tbSeminarDate.Text + "#, SeminarTime = '" + tbSeminarTime.Text +
"',SeminarLocation = '" + tbSeminarLocation.Text + "', SeminarDetails =
'" + tbSeminarDetails.Text + "', SeminarHost = '" + tbSeminarHost.Text +
"',SeminarHostEmail = '" + tbSeminarHostEmail.Text + "', SeminarType =
'" + tbSeminarType.Text + "', OrganisationNotes = '" +
tbOrganisationNotes.Text +
"' WHERE ID = " + tbID.Text;
OleDbConnection Conn = new OleDbConnection(strConnectionString);
OleDbCommand cmd = new OleDbCommand(UpdateSemSql, Conn);
try
{
cmd.Connection.Open();
int numRecordsAffected = cmd.ExecuteNonQuery();
if (numRecordsAffected == 0)
{
Response.Write("Didnt update the record, an error has occured<BR><BR>");
}
else
{
Response.Redirect("main page url");
}
}
catch(Exception ex)
{
Response.Write("There was an exception error" + ex + "<BR><BR>");
}
finally
{
cmd.Connection.Close();
}
}
--
_______________________________________________
DC
"You can not reason a man out of a position he did not reach through reason"
"Don't use a big word where a diminutive one will suffice."
"A man with a watch knows what time it is. A man with two watches is
never sure." Segal's Law
back to my database, am I leaving someting out? Do I need to tell the
DataAdapter to update the database somewhere?
private void btnUpdateSeminar_Click(object sender, System.EventArgs e)
{
string strConnectionString;
strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source='C:\\Program Files\\Common Files\\ODBC\\Data
Sources\\seminars.mdb';";
string UpdateSemSql = "UPDATE SeminarList SET Speaker = '" +
tbSpeaker.Text + "', SpeakerEmail = '" + tbSpeakerEmail.Text +
"', SpeakerInstitution = '" + tbSpeakerInstitution.Text +
"',SeminarTitle = '" + tbSeminarTitle.Text + "', SeminarDate = #" +
tbSeminarDate.Text + "#, SeminarTime = '" + tbSeminarTime.Text +
"',SeminarLocation = '" + tbSeminarLocation.Text + "', SeminarDetails =
'" + tbSeminarDetails.Text + "', SeminarHost = '" + tbSeminarHost.Text +
"',SeminarHostEmail = '" + tbSeminarHostEmail.Text + "', SeminarType =
'" + tbSeminarType.Text + "', OrganisationNotes = '" +
tbOrganisationNotes.Text +
"' WHERE ID = " + tbID.Text;
OleDbConnection Conn = new OleDbConnection(strConnectionString);
OleDbCommand cmd = new OleDbCommand(UpdateSemSql, Conn);
try
{
cmd.Connection.Open();
int numRecordsAffected = cmd.ExecuteNonQuery();
if (numRecordsAffected == 0)
{
Response.Write("Didnt update the record, an error has occured<BR><BR>");
}
else
{
Response.Redirect("main page url");
}
}
catch(Exception ex)
{
Response.Write("There was an exception error" + ex + "<BR><BR>");
}
finally
{
cmd.Connection.Close();
}
}
--
_______________________________________________
DC
"You can not reason a man out of a position he did not reach through reason"
"Don't use a big word where a diminutive one will suffice."
"A man with a watch knows what time it is. A man with two watches is
never sure." Segal's Law