开发者

i am not able to generate ID for user

I want to generate id. My application works in 3-tier (using asp.net & vs 2008). so to do this i'm calling a method from user interface(webpg1.aspx.cs) written in class1.cs file. I have assumed that there is no record in database at present, so that id could be as 1,2,3...n. So please make me where I am going wrong. Call from 开发者_开发知识库webpg1.aspx.cs

int verify = j.insertReg(ad,un,pwd); 

implementation class1.cs

public int regUser(int id, string un, string pwd)
{
  int cms = 0; 
  int id1 = 0;
  int c2 = openDb();

  if (c2 < 0)
  {
    if (ad ==0)
      id1 = callgenId(ad);

   cm = new SqlCommand("INSERT INTO regAgnt VALUES('"
                                + id1 +"','"+ un +"','"+ pwd +"')",cn);
    cms = cm.ExecuteNonQuery();
  }
  else
  {
    cms = c2;
  }

  return cms;
}

private int callgenId(int id)
{
  int idi = 0;
  cm = new SqlCommand("select MAX(aid) from regAgnt", cn);
  dr = cm.ExecuteReader();
  while (dr.Read())
  {
    if(Convert.ToInt32(dr[0])== 0)
      idi += 1;

    dr.Close();
   }
   return idi;
}

it produces output of 0 in the table, I have also bind the default value as 0 in the table.

Thanks!


If there is no info in your result set - dr.Read() doesn't happen.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜