2

詳細ビューを使用して、SQL Server データベースに合計データを挿入します。テーブルには ID という名前の主キーがあり、この pk は ID が有効になっているため、自動的に生成されます。挿入後、挿入された行の pk をフェッチする必要があり、このコードを使用します

protected void DetailsView1_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
{

    int id = Convert.ToInt32(e.Values["ID"]);
    Response.Redirect("BakhshnameAppendix.aspx?ID=" + id.ToString());
} 

しかし、それは常に 0 を返します! 挿入された ID を取得するにはどうすればよいですか?

4

1 に答える 1

0

これを使用してみてください:

protected void DetailsView1_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
{

   int intKey;
   if (int.TryParse(e.ReturnValue, out intKey))
   {
         Response.Redirect("BakhshnameAppendix.aspx?ID=" + intKey.ToString());
   }
} 
于 2012-07-02T08:08:22.227 に答える