SQLクエリからUserIdの戻り値をUsersid変数に保存します。値を取得できません.FYI UserNameはテキストです。C言語でSQL SELECTステートメントの戻り値を保存します。
int usersid;
using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["AzureSql"].ToString()))
using (SqlCommand command = new SqlCommand())
{
connection.Open();
command.CommandText = @"Select UserId from [dbo].[User] where username= @username";
command.Parameters.Clear();
command.Parameters.AddWithValue("@username", currentUser.UserName);
usersid = (int)command.ExecuteScalar();
command.CommandText = @"INSERT INTO [dbo].[ClientEmailConfirmation] ([JobNumber],[OrderNumber],[UserId]) VALUES
(@JobNumber,@OrderNumber,@UserId)";
command.Parameters.Clear();
command.Parameters.AddWithValue("@JobNumber", JobNumberTextBox.Text);
command.Parameters.AddWithValue("@OrderNumber", OrderNumberTextBox.Text);
command.Parameters.AddWithValue("@UserId", usersid);
command.ExecuteNonQuery();
}
私は大いに おかげで、
これはに答えている:[挿入された行のIDを取得するための最良の方法を?](http://stackoverflow.com/questions/42648/best-way-to-get-identity-of-inserted-row )と[挿入コマンドを実行し、Sqlで挿入されたIDを返す](http://stackoverflow.com/questions/18373461/execute-insert-command-and-return-inserted-id-in-sql) – Adrian
この質問は、 [挿入された行のIDを取得する最善の方法?](http://stackoverflow.com/questions/42648/best-way-to-get-identity-of-inserted-row)と[Insert Insertコマンドを実行し、挿入されたIDをSql](http://stackoverflow.com/questions/18373461/execute-insert-command-and-return-inserted-id-in-sql) – Adrian