TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
michin1
NA
1
0
sqldatareader in a thread
Oct 27 2003 5:11 PM
I'm having a wierd issue where i run a query in a thread and the while(Connection.read()) duplicates my results. Anyone else have this issue? For isntance if I have TestTable with the following values: TestID 1 2 3 It will console.writeline 1 1 2 2 3 3 Below is sample code: private void button3_Click(object sender, System.EventArgs e) { ThreadStart DBThread = new ThreadStart(StartDBDelegate) ; Thread DB = new Thread(DBThread) ; DB.Start(); } public void StartDBDelegate)() { Invoke(new UpdateLoadTableDelegate(RunUpdateNow)); } public void RunUpdateNow() { string source = "server=testserver;uid=testuid;pwd=testpassword;database=TestDB"; string selectconn1 = "SELECT TestID as dbTestID FROM TestTable" SqlConnection conn1 = new SqlConnection(source); conn1.Open(); SqlCommand executeconn1 = new SqlCommand(selectconn1,conn1); SqlDataReader Connection1 = executeconn1.ExecuteReader(); while(Connection1.Read()) { Console.WriteLine (Connection1[0].ToString()) } } I can reduce this menace by doing the following to the while loop, although I shouldnt have to do this...this is really bugging me. It doesnt do this outside of the thread. string strTestID = ""; while(Connection1.Read()) { if(strTestID != Connection1[0].ToString())) { Console.WriteLine (Connection1[0].ToString()) strTestID = Connection1[0].ToString()); } }
Reply
Answers (
0
)
Threading and Direct X 7