You don't create the identity before the insert. SQL Server will handle that for your. Also don't insert the identity column.
Original Solution:
using (SqlConnection sqlcon = new SqlConnection("Server")) {
using (SqlCommand myCommand = new SqlCommand("INSERT INTO cas_user_ex(fullname, email, name) VALUES(@fullname, @email, @name); SELCET SCOPE_IDENTITY();", sqlcon)) {
myCommand.Parameters.Add("@Name", Environment.UserName);
myCommand.Parameters.Add("@fullname", textBox1.Text);
myCommand.Parameters.Add("@email", textBox2.Text);
int iNewRowIdentity = Convert.ToInt32(myCommand.ExecuteScalar());
}
}
Revised Solution:
using (SqlCommand myCommand = new SqlCommand("INSERT INTO cas_user_ex(fullname, email, name) VALUES(@fullname, @email, @name); SELCET SCOPE_IDENTITY();", sqlcon.Connection)) {
myCommand.Parameters.Add("@Name", Environment.UserName);
myCommand.Parameters.Add("@fullname", textBox1.Text);
myCommand.Parameters.Add("@email", textBox2.Text);
int iNewRowIdentity = Convert.ToInt32(myCommand.ExecuteScalar());
}