473,386 Members | 1,720 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,386 software developers and data experts.

ListBox on Inserting values into the Database

5
Hi, I have been using a listbox to insert records into the database.
But I get this error when I try to add more than one records into the database :
'There is already an open DataReader associated with this Command which must be closed first.'
Can someone help me on this?

Expand|Select|Wrap|Line Numbers
  1. database.OpenConn()
  2. For j As Integer = 0 To ListBox1.Items.Count - 1
  3. Dim strSQL = "Select * FROM table1 where Name = '" & ListBox1.Items(j).ToString() & "'"
  4. Dim dr as SqlDataReader = db.ExecuteQuery(strSQL)
  5. While dr.Read()
  6. Dim ID = dr("ID").ToString()
  7. End While
  8. Next
  9. dr.Close()
  10. database.CloseConn()
  11.  
  12. database.OpenConn()
  13. Dim strSQL2 = "INSERT INTO table2 Values (" & ID & ")"
  14. database.ExecuteUpdate(strSQL2)
  15. dr.Close()
  16. database.CloseConn()
  17.  
Apr 30 '13 #1
2 3506
vijay6
158 100+
Hey Esll, open the connection to your database before line number 4 and inside the 'for' loop. And close the database connection after line number 7. Then try.
Apr 30 '13 #2
Esll
5
Hi vijay6,
I have solve the problem.
Thanks for your help anyway.
May 17 '13 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: cloverme | last post by:
Hi, I need help populating a listbox from a database on a webform. I created a an access database with a table, fields and data. Then I created a WebForm in vb.net and added a DropDownList...
1
by: pmud | last post by:
I have an ASP.NET web application using C# code. I am trying to insert values from a web form into an SQL database. I am using SQL COMMAND object for this. I need to know HOW TO INSERT THE RADIO...
6
by: Niggy | last post by:
Hi there, I would like to display the values of the index as chosen by the user in a listbox. These values would be as per the datavaluefield. On testing I get a value of -1: Private Sub...
2
by: clinttoris | last post by:
Hello, If someone could help me it would be appreciated as I am not having much luck. I'm struggling with my asp code and have some questions relating to asp and oracle database. First...
1
by: ram achar | last post by:
please send me C# code for inserting values into database sql server2005 *** Sent via Developersdex http://www.developersdex.com ***
1
by: Eva | last post by:
I need to pass listbox selected values to crystal report from .net 2005.when I am doing it the error display "The types of the parameter field and parameter field current values are not compatible."...
9
by: Bunty | last post by:
I am not beginer of this language. I've worked on this language for 2 or 3 months.But now i have a problem to inserting values in the database.It gives me error that DATABASE NOT SELECTED. I am...
6
by: Bunty | last post by:
I want to insert values in the database.If i insert values one by one then it works till 4 or 5 fields then after it gives error.In my database there are more than 20 field.Pls help me.
9
by: i12know | last post by:
Hi guys, I had some problem inserting values a structure array in C++. I had define for example struct UNITS { unsigned char VariableA; unsigned char VariableB; // the...
1
by: arvindmishra | last post by:
i m inserting values in access database it displays message value is inserted but value is not ptresent in database. I m using following code OleDbConnection cnn = new OleDbConnection(); ...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.