473,387 Members | 1,453 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Hashtable problem

AD
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
Nov 19 '05 #1
6 1073
are you calling the 'Current' on the myEnumerator? Like myEnumerator.Current

"AD" <AD@discussions.microsoft.com> wrote in message
news:3B**********************************@microsof t.com...
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

Nov 19 '05 #2
AD
No. How does that work with insert?
Thanks
Anand

"Vaibhav" wrote:
are you calling the 'Current' on the myEnumerator? Like myEnumerator.Current

"AD" <AD@discussions.microsoft.com> wrote in message
news:3B**********************************@microsof t.com...
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


Nov 19 '05 #3
see here

http://msdn.microsoft.com/library/de...ratortopic.asp

"AD" <AD@discussions.microsoft.com> wrote in message
news:54**********************************@microsof t.com...
No. How does that work with insert?
Thanks
Anand

"Vaibhav" wrote:
are you calling the 'Current' on the myEnumerator? Like
myEnumerator.Current

"AD" <AD@discussions.microsoft.com> wrote in message
news:3B**********************************@microsof t.com...
> 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


Nov 19 '05 #4
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

"AD" <AD@discussions.microsoft.com> wrote in message
news:3B**********************************@microsof t.com...
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

Nov 19 '05 #5
AD
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

"William F. Robertson, Jr." wrote:
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

"AD" <AD@discussions.microsoft.com> wrote in message
news:3B**********************************@microsof t.com...
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


Nov 19 '05 #6
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
--------------------------------------------------
"AD" <AD@discussions.microsoft.com> wrote in message
news:3E**********************************@microsof t.com...
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

"William F. Robertson, Jr." wrote:
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

"AD" <AD@discussions.microsoft.com> wrote in message
news:3B**********************************@microsof t.com...
> 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


Nov 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Ricardo Pereira | last post by:
Hi, I wrote a simple program to test the "out-of-the-box" functionalities of the CMAB (Configuration Management Application Block). After having added 2 values to an hashtable, and having written...
5
by: francois | last post by:
First of all I would to to apologize for resending this post again but I feel like my last post as been spoiled Here I go for my problem: Hi, I have a webservice that I am using and I would...
7
by: Joseph Lee | last post by:
Hi All, I am having problem when i am using hashtable to keep an array of bytes value as keys. Take a look at the code snippet below --------------------------------------------------- ...
5
by: Cyrus | last post by:
I have a question regarding synchronization across multiple threads for a Hashtable. Currently I have a Threadpool that is creating worker threads based on requests to read/write to a hashtable....
33
by: Ken | last post by:
I have a C# Program where multiple threads will operate on a same Hashtable. This Hashtable is synchronized by using Hashtable.Synchronized(myHashtable) method, so no further Lock statements are...
9
by: Oberon | last post by:
My HashTable (Global.Games) is a static collection of objects of type Game. A Game object has 8 fields (exposed as properties). The key to the HashTable is also one of these fields (GameID, of type...
7
by: J L | last post by:
I have defined a structure private structure FieldInfo dim FieldName as string dim OrdinalPostioin as Integer dim DataType as Type dim Size as Integer end structure I read this information...
7
by: SevDer | last post by:
Hi We have a static hashtable that is located in another tier in our n-tiered web application. And we are storing big but not huge objects in this hashtable and the key to the objects is...
2
by: PAzevedo | last post by:
I have this Hashtable of Hashtables, and I'm accessing this object from multiple threads, now the Hashtable object is thread safe for reading, but not for writing, so I lock the object every time I...
12
by: =?Utf-8?B?SnVsaWEgQg==?= | last post by:
Hi all I'm creating a hashtable of a list of users in AD. The keys are UserID and Password. I want to loop through the table to compare the userID and password with values that a user has...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.