StudentテーブルからStudentIDを取得し、それをデータリーダーまたはデータセットに保存し、それを使用して別のテーブルであるUsersテーブルを更新する方法を知っている人はいますか?ユーザーのユーザー名とパスワードをデフォルトとしてStudentIDにします。 。ところで、これはC#ASP.NETです。これが私のコードです。
SqlConnection conUpdate = new SqlConnection(GetConnectionString());
conUpdate.Open();
SqlCommand com2 = new SqlCommand();
com2.Connection = conUpdate;
com2.CommandText = "SELECT Students.StudentID, Users.UserID FROM Students, Users " +
"WHERE Students.UserID = Users.UserID";
int UserId = ((int)com2.ExecuteScalar());
com2.CommandText = "SELECT MAX(StudentID) FROM Students";
int StudentId = ((int)com2.ExecuteScalar());
com2.CommandType = CommandType.Text;
com2.CommandText = "UPDATE Users SET UserName=@UserName, Password=@Password WHERE UserID=@UserID";
com2.Parameters.Add("@UserName", SqlDbType.NVarChar);
com2.Parameters.Add("@Password", SqlDbType.NVarChar);
com2.Parameters[0].Value = reader;
com2.Parameters[1].Value = reader;
com2.ExecuteNonQuery();
conUpdate.Close();
conUpdate.Dispose();