Results 1 to 8 of 8

Thread: [RESOLVED] Update OleDB Code Error

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2009
    Location
    Milan
    Posts
    810

    Resolved [RESOLVED] Update OleDB Code Error

    I'm trying to updatesome records, currently my table is blank apart from the user id which is correct. but i get the error below.

    My UserSettings table is as follows

    ID is a Integer
    MonthID is a Integer
    YearID is a Integer
    UserName is a string
    Balance is a Integer
    PhotoAddress is a string
    GameSpeed is a Integer

    This is my code and below that is my error in my ErrorTXT box.

    Anyidea what is wrong?

    vb.net Code:
    1. Try
    2.  
    3.             Using connection As New OleDb.OleDbConnection(My.Settings.AirlineConnectionString)
    4.                 Using command As New OleDb.OleDbCommand("UPDATE UserSettings SET MonthID = @MonthID, YearID = @YearID, UserName = @UserName, Balance = @Balance, PhotoAddress = @PhotoAddress, GameSpeed = @GameSpeed WHERE UserID = " & CInt(GameMainWindow.ValuesUserIDTxt.Text), connection)
    5.                     connection.Open()
    6.  
    7.                     command.Parameters.AddWithValue("@ID", CInt(GameMainWindow.ValuesUserIDTxt.Text))
    8.                     command.Parameters.AddWithValue("@MonthID", CInt(GameMainWindow.ValuesGameMonthTxt.Text))
    9.                     command.Parameters.AddWithValue("@YearID", CInt(GameMainWindow.ValuesGameYearTxt.Text))
    10.                     command.Parameters.AddWithValue("@UserName", GameMainWindow.ValuesUserNameTxt.Text)
    11.                     command.Parameters.AddWithValue("@Balance", CInt(GameMainWindow.ValuesBalanceTxt.Text))
    12.                     command.Parameters.AddWithValue("@PhotoAddress", GameMainWindow.ValuesPhotoAddressTxt.Text)
    13.                     command.Parameters.AddWithValue("@GameSpeed", CInt(GameMainWindow.ValuesGameSpeedTxt.Text))
    14.  
    15.                     command.ExecuteNonQuery()
    16.                     connection.Close()
    17.                 End Using
    18.             End Using
    19.  
    20.         Catch ex As Exception
    21.             GameMainWindow.ErrorTXT.Text = ex.ToString
    22.         End Try


    Code:
    System.Data.OleDb.OleDbException: Data type mismatch in criteria expression.
       at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr)
       at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
       at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
       at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
       at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
       at System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
       at Airline_Sim.MainMod.SaveGame() in C:\Documents and Settings\Me\My Documents\Visual Studio 2008\Projects\Airliine Sim\Airliine Sim\GameData\MainMod.vb:line 25

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2009
    Location
    Milan
    Posts
    810

    Re: Update OleDB Code Error

    I've updated my code and I get no errors, however the information is not saving into my database. Why?
    vb.net Code:
    1. Try
    2.  
    3.             Using connection As New OleDb.OleDbConnection(My.Settings.AirlineConnectionString)
    4.                 Using command As New OleDb.OleDbCommand("UPDATE UserSettings SET MonthID = @MonthID, YearID = @YearID, UserName = @UserName, Balance = @Balance, PhotoAddress = @PhotoAddress, GameSpeed = @GameSpeed WHERE UserID = @UserID", connection)
    5.                     connection.Open()
    6.  
    7.                     command.Parameters.AddWithValue("@UserID", CInt(GameMainWindow.ValuesUserIDTxt.Text))
    8.                     command.Parameters.AddWithValue("@MonthID", CInt(GameMainWindow.ValuesGameMonthTxt.Text))
    9.                     command.Parameters.AddWithValue("@YearID", CInt(GameMainWindow.ValuesGameYearTxt.Text))
    10.                     command.Parameters.AddWithValue("@UserName", GameMainWindow.ValuesUserNameTxt.Text)
    11.                     command.Parameters.AddWithValue("@Balance", CInt(GameMainWindow.ValuesBalanceTxt.Text))
    12.                     command.Parameters.AddWithValue("@PhotoAddress", GameMainWindow.ValuesPhotoAddressTxt.Text)
    13.                     command.Parameters.AddWithValue("@GameSpeed", CInt(GameMainWindow.ValuesGameSpeedTxt.Text))
    14.  
    15.                     command.ExecuteNonQuery()
    16.                     connection.Close()
    17.                 End Using
    18.             End Using
    19.  
    20.         Catch ex As Exception
    21.             GameMainWindow.ErrorTXT.Text = ex.ToString
    22.         End Try
    23.     End Sub

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Update OleDB Code Error

    You have added the parameters in the wrong order - you need to ensure that they are added in the same order as they appear in the SQL statement.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2009
    Location
    Milan
    Posts
    810

    Re: Update OleDB Code Error

    I have it in this order but still does not work.

    vb.net Code:
    1. Try
    2.  
    3.             Using connection As New OleDb.OleDbConnection(My.Settings.AirlineConnectionString)
    4.                 Using command As New OleDb.OleDbCommand("UPDATE UserSettings SET MonthID = @MonthID, YearID = @YearID, UserName = @UserName, Balance = @Balance, PhotoAddress = @PhotoAddress, GameSpeed = @GameSpeed WHERE UserID = @UserID", connection)
    5.                     connection.Open()
    6.  
    7.                     command.Parameters.AddWithValue("@MonthID", CInt(GameMainWindow.ValuesGameMonthTxt.Text))
    8.                     command.Parameters.AddWithValue("@YearID", CInt(GameMainWindow.ValuesGameYearTxt.Text))
    9.                     command.Parameters.AddWithValue("@UserName", GameMainWindow.ValuesUserNameTxt.Text)
    10.                     command.Parameters.AddWithValue("@Balance", CInt(GameMainWindow.ValuesBalanceTxt.Text))
    11.                     command.Parameters.AddWithValue("@PhotoAddress", GameMainWindow.ValuesPhotoAddressTxt.Text)
    12.                     command.Parameters.AddWithValue("@GameSpeed", CInt(GameMainWindow.ValuesGameSpeedTxt.Text))
    13.                     command.Parameters.AddWithValue("@UserID", CInt(GameMainWindow.ValuesUserIDTxt.Text))
    14.  
    15.                     command.ExecuteNonQuery()
    16.                     connection.Close()
    17.                 End Using
    18.             End Using
    19.  
    20.         Catch ex As Exception
    21.             GameMainWindow.ErrorTXT.Text = ex.ToString
    22.         End Try

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Update OleDB Code Error

    There is nothing obviously wrong there... try expanding on "does not work" to give us a clue what we should be looking for.

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2009
    Location
    Milan
    Posts
    810

    Re: Update OleDB Code Error

    Well it looks okay in debugging until it gets to the ExecuteNonQuery and then it errors, says overflow?

    vb Code:
    1. System.Data.OleDb.OleDbException: Overflow
    2.    at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr)
    3.    at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
    4.    at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
    5.    at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
    6.    at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
    7.    at System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
    8.    at Airline_Sim.MainMod.SaveGame()
    This is the output?

  7. #7
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Update OleDB Code Error

    Think of it like this: If you have a 10 gallpon bucket and you try to pour 12 gallons into it, what happens? It overflows. Same thing with data. If you try to insert a 45 character data value (your 12 gallons) into a spot only intended to hold 30 characters (your 10 gallon bucket) ... it overflows. In short, something is larger than it is allowed to be.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2009
    Location
    Milan
    Posts
    810

    Re: Update OleDB Code Error

    Ohmgod, I had a Integer and not a Large Integer as my Balance is in the hundreds of millions

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width