Problems Updating my database.

Troy

Well-known member
Joined
Feb 7, 2005
Messages
153
Programming Experience
10+
Ok I know this is going to be stupid, I thought I had this figured out but it's not. When I update it adds the modifed Information to my database instead of Modifying the existing record.

I think I'm forgetting to remove the Old record before I save the new updated.

Here's my code:

VB.NET:
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] UpdateRecordButton_Click([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] UpdateRecordButton.Click[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] msg [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] HomePhone [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] OfficePhone [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] Fax [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] CellPhone [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] title [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] style [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] MsgBoxStyle[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] response [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] MsgBoxResult[/SIZE]
[SIZE=2][COLOR=#0000ff]On[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Error[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]GoTo[/COLOR][/SIZE][SIZE=2] Handler[/SIZE]
[SIZE=2]msg = [/SIZE][SIZE=2][COLOR=#a31515]"Update Record for ["[/COLOR][/SIZE][SIZE=2] & txtLastName1.Text & [/SIZE][SIZE=2][COLOR=#a31515]", "[/COLOR][/SIZE][SIZE=2] & txtFirstName1.Text & [/SIZE][SIZE=2][COLOR=#a31515]" "[/COLOR][/SIZE][SIZE=2] & txtMiddleInitial1.Text & [/SIZE][SIZE=2][COLOR=#a31515]"]?"[/COLOR][/SIZE]
[SIZE=2]style = MsgBoxStyle.YesNo[/SIZE]
[SIZE=2]title = [/SIZE][SIZE=2][COLOR=#a31515]"Save?"[/COLOR][/SIZE][SIZE=2][COLOR=#008000]' Define title.[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] IsLastNameValid() [/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]' Clear the error, if any, in the error provider.[/COLOR][/SIZE]
[SIZE=2]epName.SetError([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtLastName1, [/SIZE][SIZE=2][COLOR=#a31515]""[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] ([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtFirstName1.Text <> [/SIZE][SIZE=2][COLOR=#a31515]""[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]And[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtFirstName1.Text <> [/SIZE][SIZE=2][COLOR=#a31515]""[/COLOR][/SIZE][SIZE=2]) [/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2]UpdateRecordButton.Enabled = [/SIZE][SIZE=2][COLOR=#0000ff]True[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]' Set the error if the name is not valid.[/COLOR][/SIZE]
[SIZE=2]epName.SetError([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtLastName1, [/SIZE][SIZE=2][COLOR=#a31515]"Last Name is required."[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]UpdateRecordButton.Enabled = [/SIZE][SIZE=2][COLOR=#0000ff]False[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Exit[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] IsFirstNameValid() [/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]' Clear the error, if any, in the error provider.[/COLOR][/SIZE]
[SIZE=2]epName.SetError([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtFirstName1, [/SIZE][SIZE=2][COLOR=#a31515]""[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] ([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtLastName1.Text <> [/SIZE][SIZE=2][COLOR=#a31515]""[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]And[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtFirstName1.Text <> [/SIZE][SIZE=2][COLOR=#a31515]""[/COLOR][/SIZE][SIZE=2]) [/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2]UpdateRecordButton.Enabled = [/SIZE][SIZE=2][COLOR=#0000ff]True[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]' Set the error if the name is not valid.[/COLOR][/SIZE]
[SIZE=2]epName.SetError([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtFirstName1, [/SIZE][SIZE=2][COLOR=#a31515]"First Name is required."[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]UpdateRecordButton.Enabled = [/SIZE][SIZE=2][COLOR=#0000ff]False[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Exit[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]'Make sure they want to save changes before you exit[/COLOR][/SIZE]
[SIZE=2]response = MsgBox(msg, MsgBoxStyle.Question + style, title)[/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] response = MsgBoxResult.Yes [/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE][SIZE=2][COLOR=#008000]' User chose Yes.[/COLOR][/SIZE]
[SIZE=2]rowContact = dsContact.Tables([/SIZE][SIZE=2][COLOR=#a31515]"Contact"[/COLOR][/SIZE][SIZE=2]).NewRow[/SIZE]
[SIZE=2][COLOR=#008000]'-- Start the editing in the datarow.[/COLOR][/SIZE]
[SIZE=2]rowContact.BeginEdit()[/SIZE]
[SIZE=2][COLOR=#008000]'-- Run through the text boxes on the form, and[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]'-- if they match up with a field from the record,[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]'-- place the value back in the record.[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"LastName1"[/COLOR][/SIZE][SIZE=2]) = txtLastName1.Text[/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"FirstName1"[/COLOR][/SIZE][SIZE=2]) = txtFirstName1.Text[/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] txtMiddleInitial1.Text <> [/SIZE][SIZE=2][COLOR=#a31515]""[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"MiddleInitial1"[/COLOR][/SIZE][SIZE=2]) = txtMiddleInitial1.Text[/SIZE]
[SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"MiddleInitial1"[/COLOR][/SIZE][SIZE=2]) = Chr(32)[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] txtLastName2.Text <> [/SIZE][SIZE=2][COLOR=#a31515]""[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"LastName2"[/COLOR][/SIZE][SIZE=2]) = txtLastName2.Text[/SIZE]
[SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"LastName2"[/COLOR][/SIZE][SIZE=2]) = Chr(32)[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] txtFirstName2.Text <> [/SIZE][SIZE=2][COLOR=#a31515]""[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"FirstName2"[/COLOR][/SIZE][SIZE=2]) = txtFirstName2.Text[/SIZE]
[SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"FirstName2"[/COLOR][/SIZE][SIZE=2]) = Chr(32)[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] txtMiddleInitial2.Text <> [/SIZE][SIZE=2][COLOR=#a31515]""[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"MiddleInitial2"[/COLOR][/SIZE][SIZE=2]) = txtMiddleInitial2.Text[/SIZE]
[SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"MiddleInitial2"[/COLOR][/SIZE][SIZE=2]) = Chr(32)[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] txtCurrentStreet.Text <> [/SIZE][SIZE=2][COLOR=#a31515]""[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"CurrentStreet"[/COLOR][/SIZE][SIZE=2]) = txtCurrentStreet.Text[/SIZE]
[SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"CurrentStreet"[/COLOR][/SIZE][SIZE=2]) = Chr(32)[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] txtCurrentCity.Text <> [/SIZE][SIZE=2][COLOR=#a31515]""[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"CurrentCity"[/COLOR][/SIZE][SIZE=2]) = txtCurrentCity.Text[/SIZE]
[SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"CurrentCity"[/COLOR][/SIZE][SIZE=2]) = Chr(32)[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] txtCurrentState.Text <> [/SIZE][SIZE=2][COLOR=#a31515]""[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"CurrentState"[/COLOR][/SIZE][SIZE=2]) = txtCurrentState.Text[/SIZE]
[SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"CurrentState"[/COLOR][/SIZE][SIZE=2]) = Chr(32)[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] txtCurrentZipCode.Text <> [/SIZE][SIZE=2][COLOR=#a31515]""[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"CurrentZip"[/COLOR][/SIZE][SIZE=2]) = txtCurrentZipCode.Text[/SIZE]
[SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"CurrentZip"[/COLOR][/SIZE][SIZE=2]) = Chr(32)[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] txtCurrentCounty.Text <> [/SIZE][SIZE=2][COLOR=#a31515]""[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"CurrentCounty"[/COLOR][/SIZE][SIZE=2]) = txtCurrentCounty.Text[/SIZE]
[SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"CurrentCounty"[/COLOR][/SIZE][SIZE=2]) = Chr(32)[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] txtFutureStreet.Text <> [/SIZE][SIZE=2][COLOR=#a31515]""[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"FutureStreet"[/COLOR][/SIZE][SIZE=2]) = txtFutureStreet.Text[/SIZE]
[SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"FutureStreet"[/COLOR][/SIZE][SIZE=2]) = Chr(32)[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] txtFutureCity.Text <> [/SIZE][SIZE=2][COLOR=#a31515]""[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"FutureCity"[/COLOR][/SIZE][SIZE=2]) = txtFutureCity.Text[/SIZE]
[SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"FutureCity"[/COLOR][/SIZE][SIZE=2]) = Chr(32)[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] txtFutureState.Text <> [/SIZE][SIZE=2][COLOR=#a31515]""[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"FutureState"[/COLOR][/SIZE][SIZE=2]) = txtFutureState.Text[/SIZE]
[SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"FutureState"[/COLOR][/SIZE][SIZE=2]) = Chr(32)[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] txtFutureZipCode.Text <> [/SIZE][SIZE=2][COLOR=#a31515]""[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"FutureZip"[/COLOR][/SIZE][SIZE=2]) = txtFutureZipCode.Text[/SIZE]
[SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"FutureZip"[/COLOR][/SIZE][SIZE=2]) = Chr(32)[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] txtFutureCounty.Text <> [/SIZE][SIZE=2][COLOR=#a31515]""[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"FutureCounty"[/COLOR][/SIZE][SIZE=2]) = txtFutureCounty.Text[/SIZE]
[SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"FutureCounty"[/COLOR][/SIZE][SIZE=2]) = Chr(32)[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] txtHomePhoneAreaCode.Text <> [/SIZE][SIZE=2][COLOR=#a31515]""[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"HomePhoneAreaCode"[/COLOR][/SIZE][SIZE=2]) = txtHomePhoneAreaCode.Text[/SIZE]
[SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"HomePhoneAreaCode"[/COLOR][/SIZE][SIZE=2]) = Chr(32)[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] txtHomePhonePrefix.Text <> [/SIZE][SIZE=2][COLOR=#a31515]""[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"HomePhonePrefix"[/COLOR][/SIZE][SIZE=2]) = txtHomePhonePrefix.Text[/SIZE]
[SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"HomePhonePrefix"[/COLOR][/SIZE][SIZE=2]) = Chr(32)[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] txtHomePhoneSuffix.Text <> [/SIZE][SIZE=2][COLOR=#a31515]""[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"HomePhoneSuffix"[/COLOR][/SIZE][SIZE=2]) = txtHomePhoneSuffix.Text[/SIZE]
[SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"HomePhoneSuffix"[/COLOR][/SIZE][SIZE=2]) = Chr(32)[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] txtFaxAreaCode.Text <> [/SIZE][SIZE=2][COLOR=#a31515]""[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"FaxAreaCode"[/COLOR][/SIZE][SIZE=2]) = txtFaxAreaCode.Text[/SIZE]
[SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"FaxAreaCode"[/COLOR][/SIZE][SIZE=2]) = Chr(32)[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] txtFaxPrefix.Text <> [/SIZE][SIZE=2][COLOR=#a31515]""[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"FaxPrefix"[/COLOR][/SIZE][SIZE=2]) = txtFaxPrefix.Text[/SIZE]
[SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"FaxPrefix"[/COLOR][/SIZE][SIZE=2]) = Chr(32)[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] txtFaxSuffix.Text <> [/SIZE][SIZE=2][COLOR=#a31515]""[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"FaxSuffix"[/COLOR][/SIZE][SIZE=2]) = txtFaxSuffix.Text[/SIZE]
[SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"FaxSuffix"[/COLOR][/SIZE][SIZE=2]) = Chr(32)[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] txtCellPhoneAreaCode.Text <> [/SIZE][SIZE=2][COLOR=#a31515]""[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"CellPhoneAreaCode"[/COLOR][/SIZE][SIZE=2]) = txtCellPhoneAreaCode.Text[/SIZE]
[SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"CellPhoneAreaCode"[/COLOR][/SIZE][SIZE=2]) = Chr(32)[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] txtCellPhonePrefix.Text <> [/SIZE][SIZE=2][COLOR=#a31515]""[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"CellPhonePrefix"[/COLOR][/SIZE][SIZE=2]) = txtCellPhonePrefix.Text[/SIZE]
[SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"CellPhonePrefix"[/COLOR][/SIZE][SIZE=2]) = Chr(32)[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] txtCellPhoneSuffix.Text <> [/SIZE][SIZE=2][COLOR=#a31515]""[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"CellPhoneSuffix"[/COLOR][/SIZE][SIZE=2]) = txtCellPhoneSuffix.Text[/SIZE]
[SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"CellPhoneSuffix"[/COLOR][/SIZE][SIZE=2]) = Chr(32)[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] txtOfficePhoneAreaCode.Text <> [/SIZE][SIZE=2][COLOR=#a31515]""[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"OfficePhoneAreaCode"[/COLOR][/SIZE][SIZE=2]) = txtOfficePhoneAreaCode.Text[/SIZE]
[SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"OfficePhoneAreaCode"[/COLOR][/SIZE][SIZE=2]) = Chr(32)[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] txtOfficePhonePrefix.Text <> [/SIZE][SIZE=2][COLOR=#a31515]""[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"OfficePhonePrefix"[/COLOR][/SIZE][SIZE=2]) = txtOfficePhonePrefix.Text[/SIZE]
[SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"OfficePhonePrefix"[/COLOR][/SIZE][SIZE=2]) = Chr(32)[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] txtOfficePhoneSuffix.Text <> [/SIZE][SIZE=2][COLOR=#a31515]""[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"OfficePhoneSuffix"[/COLOR][/SIZE][SIZE=2]) = txtOfficePhoneSuffix.Text[/SIZE]
[SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"OfficePhoneSuffix"[/COLOR][/SIZE][SIZE=2]) = Chr(32)[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] txtExtension.Text <> [/SIZE][SIZE=2][COLOR=#a31515]""[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"Ext"[/COLOR][/SIZE][SIZE=2]) = txtExtension.Text[/SIZE]
[SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"Ext"[/COLOR][/SIZE][SIZE=2]) = Chr(32)[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] txtEMail.Text <> [/SIZE][SIZE=2][COLOR=#a31515]""[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"Email"[/COLOR][/SIZE][SIZE=2]) = txtEMail.Text[/SIZE]
[SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE]
[SIZE=2]rowContact([/SIZE][SIZE=2][COLOR=#a31515]"Email"[/COLOR][/SIZE][SIZE=2]) = Chr(32)[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]'-- Finish the editing of the datarow[/COLOR][/SIZE]
[SIZE=2]rowContact.EndEdit()[/SIZE]
[SIZE=2][COLOR=#008000]' dsContact.Tables("Contact").Rows.Remove(rowContact)[/COLOR][/SIZE]
[SIZE=2]dsContact.Tables([/SIZE][SIZE=2][COLOR=#a31515]"Contact"[/COLOR][/SIZE][SIZE=2]).Rows.Add(rowContact)[/SIZE]
[SIZE=2][COLOR=#008000]'-- Create an instance of the command builder[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] ocbContact [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] OleDb.OleDbCommandBuilder[/SIZE]
[SIZE=2]ocbContact = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] OleDb.OleDbCommandBuilder(daContact)[/SIZE]
[SIZE=2][COLOR=#008000]'-- Have the command builder create an Update SQL command[/COLOR][/SIZE]
[SIZE=2]daContact.UpdateCommand = ocbContact.GetUpdateCommand[/SIZE]
[SIZE=2][COLOR=#008000]'-- Perform the specified SQL command; then close the connection[/COLOR][/SIZE]
[SIZE=2]daContact.Update(dsContact, [/SIZE][SIZE=2][COLOR=#a31515]"Contact"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]dsContact.Tables([/SIZE][SIZE=2][COLOR=#a31515]"Contact"[/COLOR][/SIZE][SIZE=2]).AcceptChanges()[/SIZE]
[SIZE=2][COLOR=#008000]'-- Close the connection[/COLOR][/SIZE]
[SIZE=2]daContact.UpdateCommand.Connection.Close()[/SIZE]
[SIZE=2]MsgBox([/SIZE][SIZE=2][COLOR=#a31515]"File for "[/COLOR][/SIZE][SIZE=2] & [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].Text & [/SIZE][SIZE=2][COLOR=#a31515]" Updated!"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] Indx [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE]
[SIZE=2]System.Windows.Forms.Application.DoEvents()[/SIZE]
[SIZE=2][COLOR=#0000ff]With[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].Controls[/SIZE]
[SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][SIZE=2] Indx = 0 [/SIZE][SIZE=2][COLOR=#0000ff]To[/COLOR][/SIZE][SIZE=2] .Count - 1[/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].Controls(Indx).Tag = [/SIZE][SIZE=2][COLOR=#a31515]"1"[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].Controls(Indx).Text = [/SIZE][SIZE=2][COLOR=#0000ff]Nothing[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Next[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]With[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtLastName1.Focus()[/SIZE]
[SIZE=2]System.Windows.Forms.Application.DoEvents()[/SIZE]
[SIZE=2][COLOR=#008000]'Clear Data Table[/COLOR][/SIZE]
[SIZE=2]dsContact.Clear()[/SIZE]
[SIZE=2]dsPackage.Clear()[/SIZE]
[SIZE=2]dsService.Clear()[/SIZE]
[SIZE=2]dtContact.Clear()[/SIZE]
[SIZE=2]dtPackage.Clear()[/SIZE]
[SIZE=2]dtService.Clear()[/SIZE]
[SIZE=2]System.Windows.Forms.Application.DoEvents()[/SIZE]
[SIZE=2]cn.Close()[/SIZE]
 
[SIZE=2][COLOR=#008000]'RaiseEvent OpenFileDialog1(m_FileNames(i).ToString)[/COLOR][/SIZE]
[SIZE=2]strConnection = [/SIZE][SIZE=2][COLOR=#a31515]"Provider=Microsoft.Jet.OLEDB.4.0;Data Source = "[/COLOR][/SIZE][SIZE=2] _[/SIZE]
[SIZE=2]& dbPath[/SIZE]
[SIZE=2]cn.ConnectionString = strConnection[/SIZE]
[SIZE=2]cn.Open()[/SIZE]
[SIZE=2]System.Windows.Forms.Application.DoEvents()[/SIZE]
[SIZE=2][COLOR=#008000]' Fill the Contacts DataTable [/COLOR][/SIZE]
[SIZE=2]daContact.Fill(dsContact, [/SIZE][SIZE=2][COLOR=#a31515]"Contact"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]dtContact = dsContact.Tables.Item([/SIZE][SIZE=2][COLOR=#a31515]"Contact"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]System.Windows.Forms.Application.DoEvents()[/SIZE]
[SIZE=2][COLOR=#008000]' Fill the Package DataTable[/COLOR][/SIZE]
[SIZE=2]daPackage.Fill(dsPackage, [/SIZE][SIZE=2][COLOR=#a31515]"Package"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]dtPackage = dsPackage.Tables.Item([/SIZE][SIZE=2][COLOR=#a31515]"Package"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]System.Windows.Forms.Application.DoEvents()[/SIZE]
[SIZE=2][COLOR=#008000]' Fill the Service Table[/COLOR][/SIZE]
[SIZE=2]daService.Fill(dsService, [/SIZE][SIZE=2][COLOR=#a31515]"Service"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]dtService = dsService.Tables.Item([/SIZE][SIZE=2][COLOR=#a31515]"Service"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]System.Windows.Forms.Application.DoEvents()[/SIZE]
[SIZE=2][COLOR=#008000]'Clear TreeView Control[/COLOR][/SIZE]
[SIZE=2]frmMain.tvTreeview.Nodes.Clear()[/SIZE]
[SIZE=2]frmMain.configureTreeview()[/SIZE]
[SIZE=2]frmMain.tvTreeview.Enabled = [/SIZE][SIZE=2][COLOR=#0000ff]False[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
 
 
 
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] response = MsgBoxResult.No [/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE][SIZE=2][COLOR=#008000]' User chose No.[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Exit[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[SIZE=2]Handler:[/SIZE]
[SIZE=2]MsgBox([/SIZE][SIZE=2][COLOR=#a31515]"ERROR!"[/COLOR][/SIZE][SIZE=2] & Chr(13) & Chr(13) & [/SIZE][SIZE=2][COLOR=#a31515]"An error occurred. Error Number: "[/COLOR][/SIZE][SIZE=2] & Err.Number & _[/SIZE]
[SIZE=2][COLOR=#a31515]" Description: "[/COLOR][/SIZE][SIZE=2] & Err.Description & [/SIZE][SIZE=2][COLOR=#a31515]" Source: "[/COLOR][/SIZE][SIZE=2] & Err.Source, MsgBoxStyle.Critical, [/SIZE][SIZE=2][COLOR=#a31515]"ERROR!"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
 
You have .NET 2; there is a better way to write data access code than this. Have a read of the PQ link in my sig, then read the DW2 link, section on updating data
 
why not simply use the updatecommand of the oledbadapter i guess that makes it simpler and easy to maintain and understand, or use the commandbuilder in other manner....
 
Back
Top