SQL Query

E

Eric Kiernan

First, I don't know if this is the appropriate forum for asking SQL
questions with C#. If someone knows a more appropriate SQL group, let
me know ( they all seem geared to one vendor). I have a table ( in an
access mdb file )called Accounts, with one field, Account. I have an
List AccountList filled with unique account names. Before I add them to
the table, I want to make sure they are not already there. My first
failed select ( it blew up on the ExecuteReader is the first commented
out line. It used parameters, error "No value given for one or more
required parameters". Next commented out line, I tried the old VB6 way
of building a comand string with the apostrophe ' mark around the value.
That blew up ( now it doesn't blow for some reason). Then i bracketed
the field Account with [Account] which was successful, executed the
ExecuteReader, and did the INSERT ( with parameters), because the reader
had no rows. From every iteration after, when I do the ExecuteReader,
the reader claims it has rows, and never does another insert. It's
almost as if the reader doesn't clear out the previous result. The
connection is already open prior to executing this code. Help! on many
different levels. Sorry for being so long winded.

private void checkAccount()
---------------------------
OleDbDataReader reader;
int j;
for (int i = 0; i < AccountList.Count; i++) {
objCommand.Parameters.Clear();
objCommand.Parameters.AddWithValue("@Account", AccountList);
// objCommand.CommandText = "select * from Accounts where Acount =
@Account";
// objCommand.CommandText = "select * from Accounts where Acount = " +
"'"+ AccountList + "'";
objCommand.CommandText = "select * from Accounts where [Acount] = " +
"'"+ AccountList + "'";

reader = objCommand.ExecuteReader();
if (!reader.HasRows) {
reader.Close();
objCommand.CommandText = "INSERT INTO Accounts ( Account ) VALUES
(@Account )";
j = objCommand.ExecuteNonQuery();
}
else {
reader.Close();
}
sleep (20); // it doesn't work either if i debug step through. and i
know i shouldn't use sleep().
}
 
C

CY

        }
        sleep (20); // it doesn't work either if i debug step through.          and i
know i shouldn't use sleep().

Ehh, System.Threading.Thread.Sleep(20);
That is 20ms, can u feel that in stepping?
 
E

Eric Kiernan

What I meant is the function isn't failing because of the shortness of
the sleep(), it doesn't work either when i step through, which most
assuredly is slowing down the program more than 20 ms.
 

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

Top