|
 |
|
จะดึงข้อมูลจาก database ขึ้นมาแล้วให้ select radio button ตามค่านั้นต้องทำยังไงครับ |
|
 |
|
|
 |
 |
|
ใช้ IF ELSE ตรวจสอบ ถ้า เท่ากับ อันนี้ ให้ Checked อันนี้ ถ้า เท่ากับ อันนั้น ให้ Checked อันนั้น 
|
 |
 |
 |
 |
Date :
2014-02-11 17:28:00 |
By :
01000010 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมเข้าใจคอนเซ็บ IF ELSE นะครับ แต่ผมยังงงกับรูปแบบของ C#
รบกวนช่วยหน่อยนะครับ ข้างล่างนี่คือส่วนของฟอร์มที่เป็น radio button
ถ้าผมต้องการดึงจาก Database ออกมาจะต้องเขียนยังไงครับให้มันติ๊กตามค่า
Code (C#)
string taxrequire;
private void txttaxrequired1_CheckedChanged(object sender, EventArgs e)
{
taxrequire = "y";
}
private void txttaxrequired2_CheckedChanged(object sender, EventArgs e)
{
taxrequire = "n";
}
|
 |
 |
 |
 |
Date :
2014-02-12 08:28:04 |
By :
flintstone |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เท่าที่เห็น มีแค่ Yes กับ No (True / False) ผมแนะนำให้ใช้ checkbox นะครับ
ส่วนถ้าอยากจะใช้ radiobox จริงๆ ก็ได้ครับ ซึ่งอาจจะเก็บในฐานข้อมูลแบบ
"1" หรือ "2" หรือเป็นข้อความว่า "Yes" หรือ "No" ซึ่งส่วนนี้ใช้ IF เช็คก่อน บันทึกลงฐานข้อมูลได้
ส่วนการที่จะดึงมันขึ้นมาแสดงเราอาจจะเขียนโค้ดไว้สักเมธอดนึงเป็น เมธอด LoadData ซึ่งสามารถจะเรียกใช้ได้ตลอด
ในเมธอดนี้ เราทำอย่างไรก็ได้ให้มีข้อมูลอยู่ใน DataTable (หาใน Google พวกการ Select ต่าง ๆ)
เมื่อเรามีข้อมูลในฝั่งของโปรแกรมแล้ว เราก็จะเช็คกับคอลัมป์ TaxRequired นั้นเป็นค่าอะไร
เช่น
Code (C#)
IF DataTable[0].TaxRequired == "1"
radio1.checked = true;
else
radio2.checked = true;
ปล. ประมาณนี้นะครับ Syntax และ ชื่อ Property อาจจะไม่ถูกต้อง แต่รูปแบบประมาณนี้ (เขียนสด) 
|
 |
 |
 |
 |
Date :
2014-02-12 09:14:19 |
By :
01000010 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้แล้วครับ ขอบคุณมากครับ แต่ตอนนี้ติดปัญหา error :: myCommand.ExecuteNonQuery();
Code (C#)
SqlCommand myCommand = connection.myConnection.CreateCommand();
myCommand.CommandText = "UPDATE customer SET " + " custcode = '" + this.txtcustcode.Text + "' , custgroupcode = '" + this.txtcustgroupcode.Text + "', startdate = '" + this.txtstartdate.Value + "' , taxid = '" + this.txttaxid.Text + "' , taxrequired = '" + taxrequire + "', custstatuscode = '" + this.txtcuststatuscode.Text + "', lastupdate = '" + DateTime.Now + "', updateby = '" + bow + "', lastupdate = '" + DateTime.Now + "', updateby = '" + bow + "' " + " WHERE custcode = '" + Strcustcode + "' ";
myCommand.CommandType = CommandType.Text;
myCommand.ExecuteNonQuery();
connection.myConnection.Close();
|
 |
 |
 |
 |
Date :
2014-02-12 10:55:40 |
By :
flintstone |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Error ว่าอย่างไรครับ เบื้องต้นลอง Debug ดูค่าที่อยู่ใน myCommand.CommandText ตรวจคิวรี่ดูก่อนนะครับ
ว่าคิวรี่ที่ส่งไป Execute มีความถูกต้องหรือไม่ 
|
 |
 |
 |
 |
Date :
2014-02-12 11:01:49 |
By :
01000010 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้ละครับ ขอบคุณมากๆครับท่านสำหรับคำแนะนำ
|
ประวัติการแก้ไข 2014-02-12 13:08:31
 |
 |
 |
 |
Date :
2014-02-12 11:15:58 |
By :
flintstone |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|