Hi,
I have an update Statement that append the data in the table and create a record in the history table.
I receive the error message
The value is displayed on the TxtNationalIDUp.Text.
Please can you help!
Thanks
I have an update Statement that append the data in the table and create a record in the history table.
Code:
Private Sub UpdatedTenantDetails()
Dim conn As SqlConnection = GetDbConnection()
Dim cmd As New SqlCommand
Dim query As String
Dim Tenant_Read As New System.Data.SqlClient.SqlCommand(("Select nationalID From tblTenants where nationalID = " &
Me.TxtNationalIDUp.Text), conn)
Try
Using Autoreader As System.Data.SqlClient.SqlDataReader = Tenant_Read.ExecuteReader()
While Autoreader.Read()
Dim nationalID As String = Autoreader.GetValue(0)
For RowID = 0 To DgTenantDetails.Rows.Count - 1
If nationalID = DgTenantDetails.Rows(RowID).Cells(6).Value Then
Dim ms As New MemoryStream
PictureBox2.Image.Save(ms, PictureBox2.Image.RawFormat)
Try
query = "UPDATE dbo.tblTenants SET firstname=@firstname, lastname=@lastname, tenantfullname=@tenantfullname, telephone=@telephone, email=@email, nationalID=@nationalID, copyID=@copyID OUTPUT DELETED.firstname,DELETED.lastname,DELETED.tenantfullname,DELETED.telephone,DELETED.email,DELETED.nationalID,DELETED.copyID INTO dbo.TblTenantsHistory WHERE nationalID = @nationalID"
cmd = New SqlCommand(query, conn)
cmd.Parameters.AddWithValue("@firstname", TxtFNameUp.Text)
cmd.Parameters.AddWithValue("@lastname", TxtLNameUp.Text)
cmd.Parameters.AddWithValue("@tenantfullname", TxtFNameUp.Text & " " & TxtLNameUp.Text)
cmd.Parameters.AddWithValue("@telephone", TxtTelUp.Text)
cmd.Parameters.AddWithValue("@email", TxtEmailUp.Text)
cmd.Parameters.AddWithValue("@nationalID", TxtNationalIDUp.Text)
cmd.Parameters.Add(New SqlParameter("@copyID", SqlDbType.Image) With {.Value = ms.ToArray()})
cmd.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Information, "RCMS")
End Try
Else
End If
Next RowID
End While
End Using
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Information, "RCMS")
End Try
End Sub
Code:
Invalid Column name 'F222422'
Please can you help!
Thanks