1

我正在执行以下操作来获取插入行的标识:

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();          
    }
}

有没有办法自动获取身份?

4

0 回答 0