Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
string str = ConfigurationManager.AppSettings["constring"];
       SqlConnection con = new SqlConnection(str);



       SqlCommand cmd = new SqlCommand("insert_register", con);
       cmd.CommandType = CommandType.StoredProcedure;
       SqlParameter p1 = new SqlParameter("@EID", SqlDbType.Int);
       p1.Direction = ParameterDirection.Output;

       SqlParameter p2 = new SqlParameter("@ENAME", SqlDbType.VarChar);
       p2.Value = TextBox1.Text;
       SqlParameter p3 = new SqlParameter("@EPASSWORD", SqlDbType.VarChar);
       p3.Value = TextBox2.Text;
       SqlParameter p4 = new SqlParameter("@EREPASSWORD", SqlDbType.VarChar);
       p4.Value = TextBox3.Text;
       SqlParameter p5 = new SqlParameter("@EMAILID", SqlDbType.VarChar);
       p5.Value = TextBox4.Text;
       SqlParameter P6 = new SqlParameter("@Status", SqlDbType.VarChar);
       P6.Value = Rdbtnstatus.Text;
       SqlParameter p7 = new SqlParameter("@Verify", SqlDbType.VarChar);
       p7.Value = Rdbtnverify.Text;

       cmd.Parameters.Add(p1).Value=Convert.ToInt32(TextBox5.Text);
       cmd.Parameters.Add(p2);
       cmd.Parameters.Add(p3);
       cmd.Parameters.Add(p4);
       cmd.Parameters.Add(p5);
       cmd.Parameters.Add(P6);
       cmd.Parameters.Add(p7);


       con.Open();
       //cmd.ExecuteNonQuery();
        SqlDataReader dr;

       dr = cmd.ExecuteReader();

       if (dr.HasRows==false)
       {
         dr.Close();
       if (cmd.ExecuteNonQuery() > 0)
       {
      Label1.Text = "inserted..!";
      }
      }
      else
      {


      while (dr.Read())
      {
      TextBox1.Text = dr[0].ToString();
      TextBox2.Text = dr[1].ToString();
      TextBox3.Text = dr[2].ToString();
      TextBox4.Text = dr[3].ToString();

       Rdbtnstatus.Text = dr[3].ToString();
      Rdbtnverify.Text = dr[4].ToString();

      Label1.Text = "already existed......";
      }

       }



       con.Close();
       dr.Close();
       Random r = new Random();
       Lblmsg.Text = r.Next(10000, 100000).ToString();
       string str1 = DateTime.Now.Year.ToString();
       string str2 = DateTime.Now.ToString();
       String[] a = str2.Split('/');
       StringBuilder sb = new StringBuilder();
       sb.Append(a[0]);
       sb.Append(a[1]);
       TextBox5.Text = sb+str1+ r.Next(10000,100000).ToString();

      // string s = TextBox5.Text;

      // string str3 = s(0, 12);//u get the first 4 digits

      // int number = Convert.ToInt32(s);
       }
       }
Posted

1 solution

Is this meant to be a question ?
rajinivunnam wrote:
while (dr.Read()) { TextBox1.Text = dr[0].ToString(); TextBox2.Text = dr[1].ToString(); TextBox3.Text = dr[2].ToString(); TextBox4.Text = dr[3].ToString(); Rdbtnstatus.Text = dr[3].ToString(); Rdbtnverify.Text = dr[4].ToString(); Label1.Text = "already existed......"; }


How bizarre ? Why set the text in a textbox over and over again in a loop ? Why not just use the last value, the one you'll end up with ?

Your code is obviously a mess. I see at least five reasons why I'd fire anyone who wrote this code for me. However, if you have a question, you need to ask it. What's the issue ? Where is the issue ? What have you done to try to fix it ? What is this mess supposed to do ?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900