Friends,
I hava a Table named "EmpRegister" and
Coluumns
UId-PrimaryKey
ProfileID
UserName
Password
Mobile
Email
I need to insert an incremented value in ProfileId column(which is NOT a PrimaryKey) in a table by selecting Max(UId)+1 which IS a PrimaryKey from that same table and use cmd.Parameters.AddWithValue(.....,.....) along with other text values fetched from .aspx file.
I want to Concatenate "PM" with Max(UId)+1, for example PermanentMember and the desired value will be PM1, PM2, PM3....soon and so forth, where 1 2 3...is UID
I DONT want to use Stored Procedure in SQL Server 2008.
What I have tried:
What I did was.
protected void btnlogin_Click1(object sender, EventArgs e)
{
{
SqlConnection cn = new SqlConnection(@"Data Source=Admin-PC\SQLEXPRESS;AttachDbFilename=C:\Users\.......mdf;Integrated Security=True;User Instance=True");
String query = "Insert into EmpRegister(ProfileId,UserName,Password,Mobile,Email) SELECT MAX(UId)+1 as @ProfileID,@UserName,@Password,@Mobile,@Email)";
SqlCommand cmd = new SqlCommand(query, cn);
cmd.Parameters.AddWithValue("@UserName", txtuname.Text);
cmd.Parameters.AddWithValue("@Password", txtupass.Text);
cmd.Parameters.AddWithValue("@Mobile", mobPhone.Text);
cmd.Parameters.AddWithValue("@Email", emailID.Text);
try
{
cn.Open();
cmd.ExecuteNonQuery();
}
catch (Exception)
{
}
finally
{
cn.Close();
}
}
}
Please help me where to insert this MAX(UId)+1 value in ProfileId column.
How can I put a value in ProfileID.
Do I need a hidden textbox or any value assigned to ProfileID
cmd.Parameters.AddWithValue("@....", .........);
I tested the code without MAX(UId)+1 and removing SELECT MAX(UId)+1 as @ProfileID,@UserN...... from String query, works well.
Thanks for you time.
Ravi.