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. I did a
select for the first account,executed the ExecuteReader, and it
correctly said HasRows = false, did the INSERT. From every iteration
after, when I do the ExecuteReader, the reader claims it has rows, and
never does another insert. The ExecuteReader always returns the first
record added, and i've verified the command string is correct on each
iteration, changing the account name i'm searching for. The connection
is already open prior to executing this code. Sorry for reposting but
it really is driving me nuts.
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] = "
+ "'"+ 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);
}
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. I did a
select for the first account,executed the ExecuteReader, and it
correctly said HasRows = false, did the INSERT. From every iteration
after, when I do the ExecuteReader, the reader claims it has rows, and
never does another insert. The ExecuteReader always returns the first
record added, and i've verified the command string is correct on each
iteration, changing the account name i'm searching for. The connection
is already open prior to executing this code. Sorry for reposting but
it really is driving me nuts.
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] = "
+ "'"+ 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);
}