hi,

i m making one asp.net page. in that page there is three text boxes called id, response id, and email. same columns is in sql server table called info. In table "info" for id column i have assigned " isidentity" = yes. its created auto number like 1,2,3..... and so on for id column. now i want to assign autonumber for response id column also. sql server allows only one autonumber in one table.

User will be enter only email id in texbox called email. and rest response id column should fill automaticaly in table on click of submit button. please see the attachments. please help.

Attachments table.JPG 11.79 KB

hi,

thru code in ado.net you can use this achieve the same.
try like this

public static int GetMax_ID()
        {
            if (!connected)
                Connect();

            SqlDataAdapter da = new SqlDataAdapter("", conn);
            string query = "SELECT MAX(ID) FROM CATEGORIES";
            da.SelectCommand = new SqlCommand(query, conn);

            try
            {
                return (int)da.SelectCommand.ExecuteScalar();
            }
            catch (InvalidCastException ex)
            {
                return 0;
            }
        }
  public static int Create( string categoryname)
        {
            int Cat_ID;
            if (!connected)
                Connect();

            Cat_ID = GetMax_ID() + 1;
            SqlDataAdapter da = new SqlDataAdapter("", conn);
            string query ="insert into categories values(Cat_ID,categoryname)"
            da.InsertCommand = new SqlCommand(query, conn);
            return (int)da.InsertCommand.ExecuteNonQuery();
        }

Hi

Just make response id calculated column and drive this with ID column.
you can manipulate the value's to some extent as well.

This article has been dead for over six months. Start a new discussion instead.