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

SqlDataReader problem

115 100+
hi i am using two sqldatareader. that gives error

My code start here
Expand|Select|Wrap|Line Numbers
  1. SqlConnection conn = new SqlConnection("Data Source=**********;Initial Catalog=****; User Id=****; Password=******");
  2.         conn.Open();
  3. //collect all employee//
  4.         SqlCommand cmd = new SqlCommand("Select * from tblhrims_employeedetail where nvrresigned='no'",conn);
  5.         SqlDataReader sqldr = cmd.ExecuteReader();       
  6.  
  7.         while (sqldr.Read())
  8.         {
  9.             passstr = "";
  10.             empname =Convert.ToString(sqldr["nvrempname"]);
  11.             empnamesp = empname.Replace(" ", "");
  12.             empnamesp = empnamesp.Replace(".", "");
  13.             empnamesp = empnamesp.Substring(0, 3); 
  14.             empcode = Convert.ToString(sqldr["nvrempcode"]);
  15.  
  16.             joindate = Convert.ToDateTime(sqldr["dttdojoining"]);
  17.             joindatemonth = joindate.ToString("MMM");
  18.             joindatemonth = reverse(joindatemonth);
  19.  
  20.             RandomNumber = RandomClass.Next(100,999);
  21.  
  22.  
  23.             char ch=('\0');
  24.             StringBuilder builder = new StringBuilder();
  25.             for (int i = 0; i < size; i++)
  26.             {
  27.                 ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65)));
  28.                 builder.Append(ch);
  29.             }
  30.  
  31.              passstr = builder.ToString();
  32.  
  33.             setpassword = passstr + RandomNumber;
  34.  
  35.  
  36.             // store org password record in temp table//            
  37.             SqlCommand cmd2 = new SqlCommand("insert into tempuserpasswordtable ('empid','passwd') values ('" + empcode + "','" + setpassword + "')", conn);
  38.             SqlDataReader sqldr2 = cmd2.ExecuteReader();
  39.            // SqlDataReader sqldr2 = cmd2.ExecuteNonQuery ();
  40.  
  41.            //Store encrypt password value store in orginal table//
  42.             SqlCommand cmd3 = new SqlCommand("update tblhrims_employeedetail set nvrpassword =" + encrypt(setpassword) + " where nvrempcode=" + empcode + ")", conn);
  43.             SqlDataReader sqldr3 = cmd3.ExecuteReader();
  44.  
  45.         }
  46.  
My code End here
Mar 3 '08 #1
3 1290
kunal pawar
297 100+
what kind of error it shows ??
as per my knowledge it not allows you to open record set whn one recordset already open, u should close first one and then open second one
Mar 3 '08 #2
Plater
7,872 Expert 4TB
what kind of error it shows ??
as per my knowledge it not allows you to open record set whn one recordset already open, u should close first one and then open second one
If what kunal said is true, I would recomend that instead of your first SqlDataReader you use an SqlDataAdapter and fill a DataTable.
Then you can close up that command/query and just loop through the DataTable, performing your password insertion queries.
Mar 3 '08 #3
yogarajan
115 100+
Pls send sample

pls

Thanks
Yogarajan.G

If what kunal said is true, I would recomend that instead of your first SqlDataReader you use an SqlDataAdapter and fill a DataTable.
Then you can close up that command/query and just loop through the DataTable, performing your password insertion queries.
Mar 4 '08 #4

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

Similar topics

3
by: Ricola ! | last post by:
Why do I say: SqlDataReader dr; instead of SqlDataReader dr = new SqlDataReader();
2
by: Matthias S. | last post by:
Hi, I've written a simple app which should just fetch some data from a database and render the results into a ListView. In order to not freeze the GUI, I'm using a BackgroundWorker. The...
7
by: Franck Diastein | last post by:
Hi, when I call ExportData I have this error: Invalid attempt to Read when reader is closed. Telling me that there's a problem with this line: while(_dataR.Read()){ Code:...
3
by: Neil Guyette | last post by:
Hello, Everyone, I'm trying to find information on how to populate a combo box using a SqlDataReader. I want to be able to set the value of the combo's value property different then the...
1
by: Arvind P Rangan | last post by:
Hi All, How do you get all the values of a sqldatareader if it contains multiple resultset. Using sqldatareader.nextresult and sqldatareader.read e.g. While sqldatareader.read ' If not...
8
by: bidllc | last post by:
I have a funtion that works fine and dandy when called from anywhere in my app. It will NOT work when called from inside the class in which it resides. This is the function I'm calling:...
4
by: mimi | last post by:
Hi Please help me out, I can't find a way to close a sqldatareader when error occur at statement cmd.ExecuteReader(). I can't close it in catch because it is local in try scope and I can't...
4
by: Agnes | last post by:
I got two sub method to check some history record, Now, I found that there is some problem in Sub2() . I think the problem is about the myReader. However, I got no idea to solve it . As Sub2()...
7
by: Web learner | last post by:
I am trying to create a method GetDataFor(string column) becaues I have to repeat the same statements for several columns but I get an error as follows: The name 'dr' does not exist in the current...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.