Asp.net-C#-新增後取得主鍵自動增量最大值-SCOPE_IDENTITY()-select @@identity 的用法問題,求解!!! - C#開發 - 開發者第614926個問答
Myself
string ConStr = ConfigurationManager .ConnectionStrings["XOXOXOConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(ConStr);
conn.Open();
SqlCommand cmd = new SqlCommand( "INSERT INTO [Sign]([IdFormList],)VALUES(@IdFormList);SELECT SCOPE_IDENTITY()" , conn);
cmd.Parameters.AddWithValue( "@IdFormList", IdFormList);
string SignNewPk = cmd.ExecuteNonQuery().ToString();
this.SqlDataSource1.InsertParameters["IdSign" ].DefaultValue = SignNewPk;
cmd.Dispose();
conn.Close();
conn.Dispose();
Reference
應是 int a = int.Parse(comm.ExecuteNonQuery().ToString());
|
從 Evernote 傳送記事 |
應該是這個喔
回覆刪除ExecuteScalar()