Venkata Subbareddy

Venkata Subbareddy

  • 1k
  • 774
  • 100k

How to generate the Autounique id

May 27 2015 12:14 PM
  hi friends,
 
Iam develop the student Registration form  here student Click the Location in dropdown value  generate the  User Id  based on location  suppose
   student click Hyderbad  -------> userid = Hyd001
 student Click Hyderbad  -------> user id = Hyd002
student Click  chennai -----------> user id = che001  next  student click increment the value....
in the below iam writing the code where iam doing wrong please let me know....
protected void dpCity_SelectedIndexChanged(object sender, EventArgs e)
{

SqlConnection con = new SqlConnection("Data Source=SERVER;Initial Catalog=MuraliIIT;User ID=sa;Password=rits@1234");

string s = "select count(*) from NewStudentRegistrationForm where City ='" + dpCity.SelectedItem.Value + "'";
con.Open();
SqlCommand com = new SqlCommand(s, con);
int count = Convert.ToInt32(com.ExecuteScalar());
string city = dpCity.SelectedItem.Value;
string GeneratedId= "";
count+= 1;
if (count < 10)

GeneratedId = dpCity + "00" + count.ToString();

else if (count < 100)

GeneratedId = dpCity + "0" + count.ToString();

else

GeneratedId = dpCity + count.ToString();

TxtUserid.Text=GeneratedId;





Answers (3)