Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I am using Microsoft Access 2003 as a Database and I have encountered a really odd problem...

I am trying to UPDATE a row based on the [iD] column which is of type AUTONUMBER - sadly this isn't working at all.

 

The Database itself is as follows:

FileName: C:\DB.mdb

TableName = Players

Column: ID - Autonumber

Column: Players - Text

Column: Total - Text

 

for (int nPlayer = 1; nPlayer < nPlayersCount+1; nPlayer++)
{
oDB.Write("UPDATE [Players] SET [Players] = '" + sPlayerName + "' WHERE [iD] = '" + nPlayer + "'");
}

 

Error:

Database Error - Unable to Write:

System.Data.OleDb.OleDbException: Data type mismatch in criteria expression.

at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 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()

 

But if I try the following it works perfectly fine:

oDB.Write("UPDATE [Players] SET [Players] = '" + sPlayerName + "' WHERE [iD] = 1");

 

So the problem resides with my "WHERE [iD] = '" + nPlayer + "'" part, so I tried all the following combinations to see if one would work

oDB.Write("UPDATE [Players] SET [Players] = '" + sPlayerName + "' WHERE [iD] = '" + nPlayer.ToString() + "'");

oDB.Write("UPDATE [Players] SET [Players] = '" + sPlayerName + "' WHERE [iD] = 'nPlayer'");

None of them work, they all seem to generate the SAME error message.

 

Any help, hints, or advice would be greatly appreciated

Thanks,

Posted
But if I try the following it works perfectly fine:

oDB.Write("UPDATE [Players] SET [Players] = '" + sPlayerName + "' WHERE [iD] = 1");

 

So the problem resides with my "WHERE [iD] = '" + nPlayer + "'" part, so I tried all the following combinations to see if one would work

oDB.Write("UPDATE [Players] SET [Players] = '" + sPlayerName + "' WHERE [iD] = '" + nPlayer.ToString() + "'");

oDB.Write("UPDATE [Players] SET [Players] = '" + sPlayerName + "' WHERE [iD] = 'nPlayer'");

You're soo close....

Datatype mismatch, you're assigning an integer field with at string since you enclose nPlayer in quotes, try

oDB.Write("UPDATE [Players] SET [Players] = '" + sPlayerName + "' WHERE [iD] = " + nPlayer );

 

HTH

/Kejpa

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...