Troy
Well-known member
- Joined
- Feb 7, 2005
- Messages
- 153
- Programming Experience
- 10+
Hey all I'm having a slight issue I hope someone can help me with.
This code allows me to update my database just fine, with one exception.
If I try to delete a field and make it blank I get an error stating that it cannot be a zero length field.
How can I delete a field and update my database back to a null field.
here is my code for updating.
This code allows me to update my database just fine, with one exception.
If I try to delete a field and make it blank I get an error stating that it cannot be a zero length field.
How can I delete a field and update my database back to a null field.
here is my code for updating.
VB.NET:
Try
'-- Start the editing in the datarow.
rowContact.BeginEdit()
'-- Run through the text boxes on the form, and
'-- if they match up with a field from the record,
'-- place the value back in the record.
If txtLastName1.Text <> "" Then rowContact("LastName1") = txtLastName1.Text
If txtFirstName1.Text <> "" Then rowContact("FirstName1") = txtFirstName1.Text
If txtMiddleInitial1.Text <> "" Then rowContact("MiddleInitial1") = txtMiddleInitial1.Text
If txtLastName2.Text <> "" Then rowContact("LastName2") = txtLastName2.Text
If txtFirstName2.Text <> "" Then rowContact("FirstName2") = txtFirstName2.Text
If txtMiddleInitial2.Text <> "" Then rowContact("MiddleInitial2") = txtMiddleInitial2.Text
If txtCurrentStreet.Text <> "" Then rowContact("CurrentStreet") = txtCurrentStreet.Text
If txtCurrentCity.Text <> "" Then rowContact("CurrentCity") = txtCurrentCity.Text
If txtCurrentState.Text <> "" Then rowContact("CurrentState") = txtCurrentState.Text
If txtCurrentZipCode.Text <> "" Then rowContact("CurrentZipCode") = txtCurrentZipCode.Text
If txtCurrentCounty.Text <> "" Then rowContact("CurrentCounty") = txtCurrentCounty.Text
If txtCurrentCounty.Text <> "" Then rowContact("FutureStreet") = txtFutureStreet.Text
If txtFutureCity.Text <> "" Then rowContact("FutureCity") = txtFutureCity.Text
If txtFutureState.Text <> "" Then rowContact("FutureState") = txtFutureState.Text
If txtFutureZipCode.Text <> "" Then rowContact("FutureZipCode") = txtFutureZipCode.Text
If txtFutureCounty.Text <> "" Then rowContact("FutureCounty") = txtFutureCounty.Text
If txtHomePhoneAreaCode.Text <> "" Then rowContact("HomePhoneAreaCode") = txtHomePhoneAreaCode.Text
If txtHomePhonePrefix.Text <> "" Then rowContact("HomePhonePrefix") = txtHomePhonePrefix.Text
If txtHomePhoneSuffix.Text <> "" Then rowContact("HomePhoneSuffix") = txtHomePhoneSuffix.Text
If txtFaxAreaCode.Text <> "" Then rowContact("FaxAreaCode") = txtFaxAreaCode.Text
If txtFaxPrefix.Text <> "" Then rowContact("FaxPrefix") = txtFaxPrefix.Text
If txtFaxSuffix.Text <> "" Then rowContact("FaxSuffix") = txtFaxSuffix.Text
If txtCellPhoneAreaCode.Text <> "" Then rowContact("CellPhoneAreaCode") = txtCellPhoneAreaCode.Text
If txtCellPhonePrefix.Text <> "" Then rowContact("CellPhonePrefix") = txtCellPhonePrefix.Text
If txtCellPhoneSuffix.Text <> "" Then rowContact("CellPhoneSuffix") = txtCellPhoneSuffix.Text
If txtOfficePhoneAreaCode.Text <> "" Then rowContact("OfficePhoneAreaCode") = txtOfficePhoneAreaCode.Text
If txtOfficePhonePrefix.Text <> "" Then rowContact("OfficePhonePrefix") = txtOfficePhonePrefix.Text
If txtOfficePhoneSuffix.Text <> "" Then rowContact("OfficePhoneSuffix") = txtOfficePhoneSuffix.Text
If txtExtension.Text <> "" Then rowContact("Extension") = txtExtension.Text
If txtEMail.Text <> "" Then rowContact("Email") = txtEMail.Text
'-- Finish the editing of the datarow
rowContact.EndEdit()
If dsContact.HasChanges(DataRowState.Modified) Then
Dim dsChangedContact As DataSet
dsChangedContact = dsContact.GetChanges(DataRowState.Modified)
'-- Create an instance of the command builder
Dim ocbContact As OleDb.OleDbCommandBuilder
ocbContact = New OleDb.OleDbCommandBuilder(daContact)
'-- Have the command builder create an Update SQL command
daContact.UpdateCommand = ocbContact.GetUpdateCommand
'-- Perform the specified SQL command; then close the connection
daContact.Update(dsContact, "Contact")
dsContact.Tables("Contact").AcceptChanges()
'-- Close the connection
daContact.UpdateCommand.Connection.Close()
End If
Catch eInsertException As Exception
'Error handling goes here.
UnhandledExceptionHandler()
Exit Sub
Finally
MsgBox("File for [" & txtLastName1.Text & ", " & txtFirstName1.Text & " " & txtMiddleInitial1.Text & "] Updated!")
Me.Close()
'Clear Data Table
dsContact.Clear()
dtContact.Clear()
'RaiseEvent OpenFileDialog1(m_FileNames(i).ToString)
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " _
& dbPath & "; Persist Security Info=False"
cn.ConnectionString = strConnection
'Open the Database
cn.Open()
' Fill the Contacts DataTable
daContact.Fill(dsContact, "Contact")
dtContact = dsContact.Tables.Item("Contact")
'Close the Database
cn.Close()
'Clear TreeView Control
frmMain.tvTreeview.Nodes.Clear()
frmMain.configureTreeview()
frmMain.tvTreeview.Enabled = True
End Try
Last edited: