SqlDataAdapter Get Identity
I'm doing the following to get the identity of an inserted row:
SqlConnection con = new SqlConnetion("connectiontxc");
SqlDataAdapter adap = new SqlDataAdapter("Select * from Student");
void adap开发者_运维问答_RowUpdated(object sender, System.Data.SqlClient.SqlRowUpdatedEventArgs e)
{
if (e.StatementType == StatementType.Insert)
{
e.Row["Id"] = (new System.Data.SqlClient.SqlCommand("Select @@Identity")).ExecuteScalar();
}
}
Is there a way to get the identity automatically?
精彩评论