Re: [Newbie Question] Updating a record problem.

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



DC,

Is there a reason that you are not using a data set and a data adapter?
Creating SQL like this is a REALLY bad idea. If I entered the following
into the tbID field:

1; drop table seminarlist

You would be in big trouble.

As for why it is not updating, are you sure that the id is valid that
you are updating?

I would recommend creating a typed data set and let it generate the
parameterized query for you. It will be safer, and quite honestly, it will
reduce any errors you might get from trying to dynamically generate the SQL
yourself.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx

"DC" <sws99dsc@xxxxxxxxx> wrote in message
news:d8un3j$lk9$1@xxxxxxxxxxxxxxxxxxxxxx
> 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
>


.



Relevant Pages

  • Re: Shark to EMC
    ... I would also add that the reason it can be done is the ... TDMF will not move at the data set level to fully use larger model disks ... XRC is the only method ... I can imagine would handle mirroring as opposed to moving the data. ...
    (bit.listserv.ibm-main)
  • Re: Modify DSCB information
    ... It depends on what you want to change and the reason for the change. ... Depending on how the data set is allocated at the time, ... Products like the old STOPX37 would intercept allocation process and add ... Search the archives at http://bama.ua.edu/archives/ibm-main.html ...
    (bit.listserv.ibm-main)
  • Re: Modify DSCB information
    ... It depends on what you want to change and the reason for the change. ... this to prevent space abends or some other reason? ... Depending on how the data set is allocated at the time, ... Products like the old STOPX37 would intercept allocation process and add ...
    (bit.listserv.ibm-main)
  • Re: Remember the imminent public humiliation of Paul Smith?
    ... a detailed reason for that and point out precisely what was wrong with ... a statistically significant reduction in fatal and serious ... To my mind an 11% reduction not being statistically significant implies ... either a small data set or a very fuzzy correction method. ...
    (uk.rec.cycling)
  • Re: overcoming zero values in line graph
    ... There is no reason why you cannot have a 2nd data set that has the N/A ... Plot this second set and use the first for whatever you are ... > is still zero. ...
    (microsoft.public.excel.charting)