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
bulent
NA
15
0
There is already an open DataReader associated with this Command which must be closed first
Jun 3 2009 3:59 PM
I want to get values from two columns, concatenate them, and want to write it in another column in the same row (but unfortunatly can't). There is an error on the myCmd2.ExecuteNonQuery(); line saying "There is already an open DataReader associated with this Command which must be closed first.". How can I fix it? Thanks.
SqlConnection
con =
new
SqlConnection
(
"data source=localhost\\SQLEXPRESS;Initial Catalog=dnm;integrated security=SSPI"
);
con.Open();
string
mysql1 =
"select col1,col2 from table1"
;
SqlCommand
cmd =
new
SqlCommand
(mysql1, con);
SqlDataReader
myReader =
null
;
myReader = cmd.ExecuteReader(
CommandBehavior
.CloseConnection);
while
(myReader.Read())
{
string
strUnite = myReader.GetString(0).ToString().Trim() +
"_"
+ myReader.GetString(1).ToString().Trim();
string
mysql2 =
"INSERT INTO table1(col3) VALUES ('"
+ strUnite +
"')"
;
SqlCommand
myCmd2 =
new
SqlCommand
(mysql2, con);
myCmd2.ExecuteNonQuery();
}
Reply
Answers (
12
)
Dynamically updating a control.
How to create an object whose name is variable