SqlDataReader problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yogarajan
    New Member
    • Apr 2007
    • 115

    SqlDataReader problem

    hi i am using two sqldatareader. that gives error

    My code start here
    Code:
    SqlConnection conn = new SqlConnection("Data Source=**********;Initial Catalog=****; User Id=****; Password=******");
            conn.Open();
    //collect all employee//
            SqlCommand cmd = new SqlCommand("Select * from tblhrims_employeedetail where nvrresigned='no'",conn);
            SqlDataReader sqldr = cmd.ExecuteReader();       
            
            while (sqldr.Read())
            {
                passstr = "";
                empname =Convert.ToString(sqldr["nvrempname"]);
                empnamesp = empname.Replace(" ", "");
                empnamesp = empnamesp.Replace(".", "");
                empnamesp = empnamesp.Substring(0, 3); 
                empcode = Convert.ToString(sqldr["nvrempcode"]);
                
                joindate = Convert.ToDateTime(sqldr["dttdojoining"]);
                joindatemonth = joindate.ToString("MMM");
                joindatemonth = reverse(joindatemonth);
                
                RandomNumber = RandomClass.Next(100,999);
    
                
                char ch=('\0');
                StringBuilder builder = new StringBuilder();
                for (int i = 0; i < size; i++)
                {
                    ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65)));
                    builder.Append(ch);
                }
    
                 passstr = builder.ToString();
              
                setpassword = passstr + RandomNumber;
    
    
                // store org password record in temp table//            
                SqlCommand cmd2 = new SqlCommand("insert into tempuserpasswordtable ('empid','passwd') values ('" + empcode + "','" + setpassword + "')", conn);
                SqlDataReader sqldr2 = cmd2.ExecuteReader();
               // SqlDataReader sqldr2 = cmd2.ExecuteNonQuery ();
    
               //Store encrypt password value store in orginal table//
                SqlCommand cmd3 = new SqlCommand("update tblhrims_employeedetail set nvrpassword =" + encrypt(setpassword) + " where nvrempcode=" + empcode + ")", conn);
                SqlDataReader sqldr3 = cmd3.ExecuteReader();
    
            }
    My code End here
    Last edited by Plater; Mar 3 '08, 02:33 PM. Reason: added [CODE] tags
  • kunal pawar
    Contributor
    • Oct 2007
    • 297

    #2
    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

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      Originally posted by kunal pawar
      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.

      Comment

      • yogarajan
        New Member
        • Apr 2007
        • 115

        #4
        Pls send sample

        pls

        Thanks
        Yogarajan.G

        Originally posted by Plater
        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.

        Comment

        Working...