私は、ASP.NETでc#とSQL Server 2005をバックエンドとしてプロジェクトを開発しています。それは、データベースからユーザの情報を表示するページprofile.aspx
を含む。セッション変数は、現在ログインしているユーザーを追跡するために使用されます。データベース内更新クエリの後に値が更新されない
profiles
テーブル等dept, address, contact, skills, interests
ようusername
列と10他の人の列などが含まれてい
私はprofile.aspx
上のすべてのこれらの値を表示しています。別のページは、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そのボタンを押してください(コード)。 – Vache
更新ステートメントが間違ったレコードを更新しています。 (またはレコードがない)正常に終了します。現在の質問の質問に答えることができます。 – Randy
そのボタンをクリックすると、「profile.aspx」というページが表示されます。しかし、それは更新されていない古い値を含んでいます! –