Problem updating Access Database

  • Thread starter Thread starter delta7
  • Start date Start date
D

delta7

Hi,

I'm new to C sharp and currently writing a small program that uses an Access 2003
database.

I am currently having a problem when updating a row that includes numeric data.

When updating just the text fields in the row everything works fine with the
following command:


dbCommand.CommandText = "UPDATE ScanLibTable SET Regex = '" +
txtRegex.Text.ToString () + "', Description = '" +
txtDescription.Text.ToString () + "' WHERE Key = " +
intCurrentKey.ToString () + ";" ;


but when attempting to also update a numeric field with the index value from a
drop down list I get an except because the UPDATE command is invalid:

int intLang = lstLanguage.SelectedIndex;

dbCommand.CommandText = "UPDATE ScanLibTable SET Regex = '" +
txtRegex.Text.ToString () + "', Description = '" +
txtDescription.Text.ToString () + "', Language = " +
intLang.ToString() + " WHERE Key = " + intCurrentKey.ToString () + ";" ;


Can someone point out what I'm doing wrong?

Cheers
--
 
delta7 said:
Hi,

I'm new to C sharp and currently writing a small program that uses an
Access 2003
database.

I am currently having a problem when updating a row that includes numeric
data.

When updating just the text fields in the row everything works fine with
the
following command:


dbCommand.CommandText = "UPDATE ScanLibTable SET Regex = '" +
txtRegex.Text.ToString () + "', Description = '" +
txtDescription.Text.ToString () + "' WHERE Key = " +
intCurrentKey.ToString () + ";" ;


but when attempting to also update a numeric field with the index value
from a
drop down list I get an except because the UPDATE command is invalid:

int intLang = lstLanguage.SelectedIndex;

dbCommand.CommandText = "UPDATE ScanLibTable SET Regex = '" +
txtRegex.Text.ToString () + "', Description = '" +
txtDescription.Text.ToString () + "', Language = " +
intLang.ToString() + " WHERE Key = " + intCurrentKey.ToString () + ";" ;


Can someone point out what I'm doing wrong?

Well, waht exception were you recieving? Is the data different between the
two? Have you tried the second sequence using literal values instead of
using all teh variables?

I can't say whats wrong without more information.

Also, FYI, you don't need all of those ToString() calls there. The text
members are already strings and the compiler will call ToString()
automatically on the integers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top