작동하지만 작동하지 않습니다. 여기 그것은 나에게 이전 업데이트 이전의 값을 보여줍니다 내 코드SQL 서버에서 테이블을 업데이트하려고하지만 내가 SQL 서버에서 테이블을 업데이트하려고
SqlConnection conn;
string connString = ConfigurationManager.ConnectionStrings["Alumnidb"].ConnectionString;
string userName;
SqlCommand cmdProfile, cmdUpdate;
SqlDataReader reader;
string UserId;
protected void Page_Load(object sender, EventArgs e)
{
userName = Request.QueryString["UserName"].ToString();
RetriveProfile();
}
protected void RetriveProfile()
{
conn = new SqlConnection(connString);
cmdProfile = new SqlCommand("SELECT Name, UserId FROM UserProfile WHERE [email protected]",conn);
cmdProfile.Parameters.AddWithValue("@UserName",userName);
conn.Open();
reader = cmdProfile.ExecuteReader();
while (reader.Read())
{
TextBoxName.Text = reader["Name"].ToString();
UserId = reader["UserId"].ToString();
}
conn.Close();
}
protected void buttonUpdate_Click(object sender, EventArgs e)
{
conn = new SqlConnection(connString);
cmdUpdate = new SqlCommand("UPDATE UserProfile SET [email protected] WHERE [email protected]",conn);
cmdUpdate.Parameters.AddWithValue("@UserId",UserId);
cmdUpdate.Parameters.AddWithValue("@Name",TextBoxName.Text.ToString());
conn.Open();
cmdUpdate.ExecuteScalar();
conn.Close();
}
과에서 .aspx 파일
Name: <asp:TextBox ID="TextBoxName" runat="server" ></asp:TextBox>
<asp:Button ID="buttonUpdate" runat="server" Text="UpDate"
onclick="buttonUpdate_Click"/>
입니다. . 나는 SQL 서버를 체크하고 거기에도 변화가 없다. 내가 뭘 잘못하고 있니? 귀하의 도움을 주실 수 있습니다. . .Thanx
시도'cmdUpdate.ExecuteNonQuery();' – Tim
은'userName'이 제대로 값을 받고? – PiLHA
시도했지만 여전히 동일한 결과가 나타납니다. – user2517610