开发者

SqlDataAdapter Get Identity

开发者 https://www.devze.com 2023-03-22 21:00 出处:网络
I\'m doing the following to get the identity of an inserted row: SqlConnection con = new SqlConnetion(\"connectiontxc\");

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?

0

精彩评论

暂无评论...
验证码 换一张
取 消