My table ID is an auto-increment column, I want to get the ID when I insert the record. how can I do so?
this is how I insert the record:
ds.InsertCommand = "INSERT INTO Cases (pName,sDate,pAge,sAge,dAge,sex,status)
VALUES ('" + pname.Text + "','" + sdate.Text + "'," + patAge.Text + "," + sage.Text + "," + dage.Text + ",'" + sex.SelectedValue + "','Draft')";
ds.Insert();
ds is an SqlDataSource
Use
SCOPE_IDENTITY()Using a SQLCommand:
It’s also worth noting that you should parametize your queries to avoid SQL Injection