Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

any ideas why this won't save

Status
Not open for further replies.

UKmedia

Programmer
Nov 2, 2002
90
Code:
Dim strSQL As String

        'Update Existing
        strSQL = "UPDATE cashier SET FullName = '" & txtName.Text & "', Address = '" & txtAddress.Text & "', Telephone = '" & txtContact.Text & "', Age = '" & txtAge.Text & "', NI = '" & txtNI.Text & "', EContact = '" & txtEContact.Text & "', EName = '" & txtEName.Text & "', ERelationship = '" & txtERelationship.Text & "' WHERE Code=" & "'" & CLng(Me.lvEmployees.SelectedItems(0).Tag) & "'"
        Dim ocon As OleDbConnection = New OleDbConnection(DB_Connect)
        ocon.Open()

        Dim ocmd As OleDbCommand = New OleDbCommand(strSQL, ocon)
        ocmd.ExecuteNonQuery()

        ocmd.Dispose()
        ocon.Close()

        MessageBox.Show("Saved Details", "Saved", MessageBoxButtons.OK, MessageBoxIcon.Information)

I get error:

Data type mismatch in criteria expression.
 

Do yourself a favor and try:
Code:
Dim strSQL As String

        'Update Existing
        strSQL = "UPDATE cashier SET FullName = '" & txtName.Text & "', Address = '" & txtAddress.Text & "', Telephone = '" & txtContact.Text & "', Age = '" & txtAge.Text & "', NI = '" & txtNI.Text & "', EContact = '" & txtEContact.Text & "', EName = '" & txtEName.Text & "', ERelationship = '" & txtERelationship.Text & "' WHERE Code=" & "'" & CLng(Me.lvEmployees.SelectedItems(0).Tag) & "'"

    [red][b]Debug.Print strSQL[/b][/red]

        Dim ocon As OleDbConnection = New OleDbConnection(DB_Connect)
        ocon.Open()

        Dim ocmd As OleDbCommand = New OleDbCommand(strSQL, ocon)
        ocmd.ExecuteNonQuery()

        ocmd.Dispose()
        ocon.Close()

        MessageBox.Show("Saved Details", "Saved", MessageBoxButtons.OK, MessageBoxIcon.Information)
and see what you are trying to execute.

Most of the time you can spot the problem in your SQL.


Have fun.

---- Andy
 
i have done this but cannot see where.
 
Two things jump out.....AGE and CODE. Are these truly text values??? You are passing them text and either of them could be numeric based on the names....

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
VB.NET Programmer
 
The mistake should be here
Code:
strSQL = "UPDATE cashier SET FullName = '" & txtName.Text & "'
, Address = '" & txtAddress.Text & "'
, Telephone = '" & txtContact.Text & "'
, Age = '" & txtAge.Text & "'
, NI = '" & txtNI.Text & "'
, EContact = '" & txtEContact.Text & "'
, EName = '" & txtEName.Text & "'
, ERelationship = '" & txtERelationship.Text & "' 
[COLOR=red]WHERE Code=" & "'" & CLng(Me.lvEmployees.SelectedItems(0).Tag) & "'"[/color]
You are passing a Integer like string. try changing to
Code:
[COLOR=green]WHERE Code=" & CLng(Me.lvEmployees.SelectedItems(0).Tag) [/color]


________________________________________________________
Zameer Abdulla
Help to find Missing people
 
that worked cheers,

It was also down to me trying to enter in a text item into a number field too.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top