Hi - im getting the following error message when running my program. It happens when i click the update button which is supposed to update the database:
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll
Additional information: System error.
The code is:
Dim SQL As System.Data.SqlClient.SqlCommand
SQL = Me.SqlConnection1.CreateCommand
Dim Leg As Integer
Dim T As String
T = "Update Postbook Set name='" & txtName.Text & "',"
T = T & "contact = '" & txtContact.Text & "',"
T = T & "ref = '" & txtRef.Text & "',"
T = T & "File Ref = '" & txtFileRef.Text & "',"
Dim myAddress As Array
myAddress = Split(txtAddress.Text, vbCrLf)
'FILL ADDRESS1
If UBound(myAddress) > 0 Then
T = T & "address1='" & myAddress(0) & "',"
Else
T = T & "address1='',"
End If
'FILL ADDRESS2
If UBound(myAddress) >= 1 Then
T = T & "address2='" & myAddress(1) & "',"
Else
T = T & "address2='',"
End If
'FILL ADDRESS3
If UBound(myAddress) >= 2 Then
T = T & "address3='" & myAddress(2) & "',"
Else
T = T & "address3='',"
End If
'FILL ADDRESS4
If UBound(myAddress) >= 3 Then
T = T & "address4='" & myAddress(3) & "',"
Else
T = T & "address4='',"
End If
T = T & "subject = '" & txtSubject.Text & "',"
T = T & "section = '" & cboSection.Text & "',"
T = T & "rec_date = '" & dtp1.Value & "',"
T = T & "amount = '" & txtAmount.Text & "',"
T = T & "re-dir = '" & chkReDir.Text & "',"
If chkReDir.Checked Then
T = T & "CheckField='Yes,'"
Else
T = T & "CheckField='No,'"
End If
T = T & "officer = '" & cboOfficer.Text & "',"
T = T & "acknow_req = '" & chkAckReq.Checked & "',"
If chkAckReq.Checked Then
T = T & "CheckField='Yes,'"
Else
T = T & "CheckField='No,'"
End If
T = T & "acknow date = '" & dtpAck.Value & "',"
T = T & "ack_sent = '" & chkAckSent.Checked & "',"
If chkAckSent.Checked Then
T = T & "CheckField='Yes,'"
Else
T = T & "CheckField='No,'"
End If
T = T & "reply req'd = '" & chkRep.Checked & "',"
If chkRep.Checked Then
T = T & "CheckField='Yes,'"
Else
T = T & "CheckField='No,'"
End If
T = T & "reply date = '" & dtpRep.Value & "',"
T = T & "notes = '" & txtNotes.Text & "' "
T = T & "where record no = " & txtRecord.Text
SQL.CommandText = T
Me.SqlConnection1.Open()
SQL.ExecuteNonQuery()
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll
Additional information: System error.
The code is:
Dim SQL As System.Data.SqlClient.SqlCommand
SQL = Me.SqlConnection1.CreateCommand
Dim Leg As Integer
Dim T As String
T = "Update Postbook Set name='" & txtName.Text & "',"
T = T & "contact = '" & txtContact.Text & "',"
T = T & "ref = '" & txtRef.Text & "',"
T = T & "File Ref = '" & txtFileRef.Text & "',"
Dim myAddress As Array
myAddress = Split(txtAddress.Text, vbCrLf)
'FILL ADDRESS1
If UBound(myAddress) > 0 Then
T = T & "address1='" & myAddress(0) & "',"
Else
T = T & "address1='',"
End If
'FILL ADDRESS2
If UBound(myAddress) >= 1 Then
T = T & "address2='" & myAddress(1) & "',"
Else
T = T & "address2='',"
End If
'FILL ADDRESS3
If UBound(myAddress) >= 2 Then
T = T & "address3='" & myAddress(2) & "',"
Else
T = T & "address3='',"
End If
'FILL ADDRESS4
If UBound(myAddress) >= 3 Then
T = T & "address4='" & myAddress(3) & "',"
Else
T = T & "address4='',"
End If
T = T & "subject = '" & txtSubject.Text & "',"
T = T & "section = '" & cboSection.Text & "',"
T = T & "rec_date = '" & dtp1.Value & "',"
T = T & "amount = '" & txtAmount.Text & "',"
T = T & "re-dir = '" & chkReDir.Text & "',"
If chkReDir.Checked Then
T = T & "CheckField='Yes,'"
Else
T = T & "CheckField='No,'"
End If
T = T & "officer = '" & cboOfficer.Text & "',"
T = T & "acknow_req = '" & chkAckReq.Checked & "',"
If chkAckReq.Checked Then
T = T & "CheckField='Yes,'"
Else
T = T & "CheckField='No,'"
End If
T = T & "acknow date = '" & dtpAck.Value & "',"
T = T & "ack_sent = '" & chkAckSent.Checked & "',"
If chkAckSent.Checked Then
T = T & "CheckField='Yes,'"
Else
T = T & "CheckField='No,'"
End If
T = T & "reply req'd = '" & chkRep.Checked & "',"
If chkRep.Checked Then
T = T & "CheckField='Yes,'"
Else
T = T & "CheckField='No,'"
End If
T = T & "reply date = '" & dtpRep.Value & "',"
T = T & "notes = '" & txtNotes.Text & "' "
T = T & "where record no = " & txtRecord.Text
SQL.CommandText = T
Me.SqlConnection1.Open()
SQL.ExecuteNonQuery()