Hashtable problem

G

Guest

Hi All
I am using a hashtable and trying to insert rows into sqlserver database.
My hashtable has 2 rows.
My code is as follows:
Dim myEnumerator As IDictionaryEnumerator = vh.GetEnumerator()
While myEnumerator.MoveNext()
SQL = "INSERT INTO Test(MyKey) VALUES ('" &
myEnumerator.Key & "')"
pmtCommand = New SqlCommand(SQL, pmtConn)
pmtCommand.ExecuteNonQuery()
End While
When I check my table Test, there are more then 2 rows..there are generally
30-40 rows (duplicates). Any idea why?
Thanks in advance.
Anand
 
W

William F. Robertson, Jr.

You code looks correct. Are you sure there are only 2 records in hash
table? You probably have run this code several times. Are you clearing
your table before executing this code?

bill
 
G

Guest

Yes there are only 2 records in hash table. But it inserts 30-40 rows only in
debug mode. If I run my application without debugging, it inserts 2 rows
exactly.
Do you know why this happens in debug mode ?

- Thanks Anand
 
A

Alvin Bruney [Microsoft MVP]

It may help to put some statements to echo the size of the hashtable before
and after to you write your data to the database. Compare them in debug and
release mode. Chances are, the issue is with some conditional logic and not
with the configuration build.

--
Regards
Alvin Bruney
[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
available at www.lulu.com/owc
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top