I want to store return value of UserId from sql query to Usersid variable.But I am not able to get the value.FYI UserName is text.
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();
}
I would greatly appreciate of your help Thanks, A