Pantip.com Pantip-TechExchange | Pantip-Cafe | PantipMarket.com | Chat | PanTown.com | BlogGang.com| Torakhong.org| GameRoom
 




แก้ไขข้อมูลกับฐานข้อมูลไม่ได้อะคับ C#

ช่วยดูโปรแกรมให้หน่อยคับ

เมื่อ page load จะดึงข้อมูลออกมา 3 ตัว เมื่อดึงมาแล้วก็จะแสดงค่าออกทาง control ต่างๆดังนี้คับ

ddl_sex.SelectedValue = dr[0].ToString();
txt_Bday.Text = dr[1].ToString();
ddl_city.SelectedValue = dr[2].ToString();

มี dropdownlist กับ textbox คับ

ซึ่งผู้ใช้สามารถแก้ไขข้อมูลที่แสดงอยู่นี้ได้เลย
และเมื่อกดปุ่ม Save ก็จะบันทึกข้อมูลลงไป

ปัญหาอยู่ที่ ข้อมูลที่ save ลงไปมันไม่เป็นข้อมุลใหม่ที่แก้ไข แต่กลับเป็นข้อมูลเก่าแทน อะ งงอะ
ทั้งๆ ข้อมูลที่อยู่ใน control เป็นค่าใหม่ไปแล้ว แต่พอกด save ข้อมูลดันเป็นข้อมูลเก่าซะงั้น

code คับ

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class basic : System.Web.UI.Page
{
SqlConnection Connection;
String selectCmd, updateCmd;
SqlCommand Command;
SqlDataReader Reader;

protected void Page_Load(object sender, EventArgs e)
{
MultiView_basic.SetActiveView(View_Edit);

Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["mxvfriendship_com_vfriendConnectionString"].ConnectionString);

selectCmd = "SELECT [basSexId], [basBday], [basHomeCityId] FROM [basic]";
selectCmd += " WHERE [basId] = '" + Session["LogId"] + "'";

SqlDataAdapter Adap = new SqlDataAdapter(selectCmd, Connection);
DataSet ds = new DataSet();
Adap.Fill(ds);
foreach (DataRow dr in ds.Tables[0].Rows)
{
ddl_sex.SelectedValue = dr[0].ToString(); //สมมุติ ค่าเก่าเป็น 0
txt_Bday.Text = dr[1].ToString(); //สมมุติ ค่าเก่าเป็น 01/01/2550
ddl_city.SelectedValue = dr[2].ToString(); //สมมุติ ค่าเก่าเป็น 0
}
}
protected void bn_save_Click(object sender, ImageClickEventArgs e)
{

updateCmd = "UPDATE [basic] SET ";
updateCmd += "[basSexId] = @basSexId, ";
updateCmd += "[basBday] = @basBday, ";
updateCmd += "[basHomeCityId] = @basHomeCityId ";
updateCmd += "WHERE [basSexId] = '" + Session["LogId"] + "'";

Command = new SqlCommand(updateCmd, Connection);

Command.Parameters.Add(new SqlParameter("@basSexId", SqlDbType.NVarChar, 1));
Command.Parameters["@basSexId"].Value = ddl_sex.SelectedValue; //ตรงนี้ก็ยังเป็น 0 ??? ทำไมไม่เป็นค่าใหม่ที่อยู่ใน cotrol
Command.Parameters.Add(new SqlParameter("@basBday", SqlDbType.NVarChar, 10));
Command.Parameters["@basBday"].Value = txt_Bday.Text; //ตรงนี้ก็ยังเป็น 01/01/2550 ??? ทำไมไม่เป็นค่าใหม่ที่อยู่ใน cotrol
Command.Parameters.Add(new SqlParameter("@basHomeCityId", SqlDbType.NVarChar, 2));
Command.Parameters["@basHomeCityId"].Value = ddl_city.SelectedValue; //ตรงนี้ก็ยังเป็น 0 ??? ทำไมไม่เป็นค่าใหม่ที่อยู่ใน cotrol

Command.Connection.Open();
Command.ExecuteNonQuery();
Command.Connection.Close();

MultiView_basic.SetActiveView(View_Save);
}
}


จากคุณ : tu -[ 30 ต.ค. 50 - 11:20:00 A:202.57.177.114 X: ]




ข้อความหรือรูปภาพที่ปรากฏในกระทู้ที่ท่านเห็นอยู่นี้ เกิดจากการตั้งกระทู้และถูกส่งขึ้นกระดานข่าวโดยอัตโนมัติจากบุคคลทั่วไป ซึ่ง PANTIP.COM มิได้มีส่วนร่วมรู้เห็น ตรวจสอบ หรือพิสูจน์ข้อเท็จจริงใดๆ ทั้งสิ้น หากท่านพบเห็นข้อความ หรือรูปภาพในกระทู้ที่ไม่เหมาะสม กรุณาแจ้งทีมงานทราบ เพื่อดำเนินการต่อไป
Considering the real-time nature of this webboard, it is impossible for us to review all messages/post. Please remember that we do not actively monitor the contents of and are not responsible for any messages posted. Anyone who feels that a posted message is inappropriate, Please encouraged to contact us immediately by email at kratoo@pantip.com , and We will remove objectionable messages within a reasonable time frame.



Pantip-Cafe | Pantip-TechExchange | PantipMarket.com | PanTown.com | BlogGang.com