ASP.NET에서 C# 및 SQL Server 2005를 백엔드로 사용하여 프로젝트를 개발 중입니다. 그것은 데이터베이스에서 사용자의 정보를 표시하는 페이지 profile.aspx
을 포함합니다. 세션 변수는 현재 로그인 한 사용자를 추적하는 데 사용됩니다.업데이트 쿼리 후 값이 업데이트되지 않습니다.
데이터베이스의 profiles
표 profile.aspx
에 dept, address, contact, skills, interests
등 등
내가 표시하고 모든 값과 같은 username
열 및 10 다른 열이 포함되어 있습니다. 다른 페이지는 profile.aspx
의 편집 버튼을 클릭하면 나타나는 edit_profile.aspx
입니다. 여기서 데이터는 텍스트 상자에 표시되며 이미 편집 된 이전 항목이 표시되며 Update
버튼을 클릭하여 확인합니다.
업데이트 쿼리가 제대로 실행되고 오류는 없지만 값은 데이터베이스 테이블에서 업데이트되지 않습니다. 가능한 이유는 무엇입니까? 해결책?
감사합니다protected void Page_Load(object sender, EventArgs e)
{
string CNS = ConfigurationManager.ConnectionStrings["myconn"].ToString();
SqlConnection con = new SqlConnection(@CNS);
SqlDataAdapter sda = new SqlDataAdapter("select * from profiles where username='" + Session["currentusername"].ToString()+"'", con);
DataSet ds = new DataSet();
sda.Fill(ds, "profiles");
txt_name.Text = ds.Tables["profiles"].Rows[0][0].ToString();
txt_deptt.Text = ds.Tables["profiles"].Rows[0][1].ToString();
txt_qualificatns.Text = ds.Tables["profiles"].Rows[0][2].ToString();
txt_add.Text = ds.Tables["profiles"].Rows[0][3].ToString();
txt_contacts.Text = ds.Tables["profiles"].Rows[0][4].ToString();
txt_interests.Text = ds.Tables["profiles"].Rows[0][5].ToString();
txt_awards.Text = ds.Tables["profiles"].Rows[0][6].ToString();
txt_website.Text = ds.Tables["profiles"].Rows[0][7].ToString();
txt_skills.Text = ds.Tables["profiles"].Rows[0][8].ToString();
txt_mstatus.Text = ds.Tables["profiles"].Rows[0][9].ToString();
ds.Reset();
}
protected void Button1_Click(object sender, EventArgs e)
{
string CNS = ConfigurationManager.ConnectionStrings["myconn"].ToString();
SqlConnection con = new SqlConnection(@CNS);
SqlCommand sda = new SqlCommand("update profiles set department='"+txt_deptt.Text+"',qualifications='"+txt_qualificatns.Text+"', address='"+txt_add.Text+"', contacts='"+txt_contacts.Text+"', interests='"+txt_interests.Text+"', awards='"+txt_awards.Text+"', website='"+txt_website.Text+"', skills='"+txt_skills.Text+"', mstatus='"+txt_mstatus.Text+"' where username='" + Session["currentusername"].ToString() + "'", con);
DataSet ds = new DataSet();
try
{
con.Open();
int temp=sda.ExecuteNonQuery();
con.Close();
if (temp >= 1)
{
lbl_message.ForeColor = System.Drawing.Color.Green;
lbl_message.Text = "Profile Updated Successfully!";
}
else
{
lbl_message.ForeColor = System.Drawing.Color.Red;
lbl_message.Text = "Integer less than 1";
}
}
catch
{
lbl_message.ForeColor = System.Drawing.Color.Red;
lbl_message.Text = "Try Again Later, An Error Occured!";
}
//Response.Redirect("profile.aspx");
}
}
이 때 발생하는 우리에게 보여주십시오 너 cl ick 그 버튼 (코드). – Vache
업데이트 문이 잘못된 레코드를 업데이트하고 있습니다. (또는 레코드 없음). 현재 질문에 대답 할 수 있습니다. – Randy
버튼을 클릭하면 "profile.aspx"페이지가 나타납니다! 그러나 그것은 아무것도 업데이트되지 않은 이전 값을 포함합니다! –