|
 |
|
จะทำการ edit multicheckbox โดยให้ Return checked เหมือนตอนที่เรา checked ก่อน insert ซึ่งเก็บข้อมูลเป็น Array จะมีวิธีแบบไหนบ้างครับ |
|
 |
|
|
 |
 |
|
จะเพิ้มขั้นตอนไหนครับ ขอ Code ประกอบด้วยครับ
|
 |
 |
 |
 |
Date :
2014-07-10 14:00:50 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
รายละเอียด
Form

ผมทำการ insert multi checkbox ลงในฟิวด์เดียว โดยใช้ Code แบบนี้
Code (C#)
try
{
string StrCon = "Data Source= PROGRAMMER03\\SQLSERVER02;Initial Catalog=DBManage;Integrated Security=SSPI;";
SqlConnection cn = new SqlConnection(StrCon);
cn.Open();
string strCheckValue = "";
if (checkBox1.Checked)
{
strCheckValue = strCheckValue + "," + checkBox1.Text;
}
if (checkBox2.Checked)
{
strCheckValue = strCheckValue + "," + checkBox2.Text;
}
if (checkBox3.Checked)
{
strCheckValue = strCheckValue + "," + checkBox3.Text;
}
if (checkBox4.Checked)
{
strCheckValue = strCheckValue + "," + checkBox4.Text;
}
if (checkBox5.Checked)
{
strCheckValue = strCheckValue + "," + checkBox5.Text;
}
if (checkBox6.Checked)
{
strCheckValue = strCheckValue + "," + checkBox6.Text;
}
//label1.Text = strCheckValue = strCheckValue.TrimStart(',');
string Data = strCheckValue = strCheckValue.TrimStart(',').ToString();
string query = "INSERT INTO tbl_Product(Name_Pro)VALUES(@Data)";
SqlCommand sqlCommand = new SqlCommand(query, cn);
sqlCommand.Connection = cn;
sqlCommand.Parameters.AddWithValue(@"Data", Data);
sqlCommand.ExecuteNonQuery();
MessageBox.Show("บันทึกฐานข้อมูลเรียบร้อย");
cn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
ผลลัพธ์ที่ได้ :

ความต้องการคือ ผมจะทำการ edit checkbox จาก database
ซึ่งผมต้องการ split comma ในข้อมูลที่อยู่ในฟิวด์เดียว และทำการ checked item จากข้อมูลที่มีอยู่ในฟิวด์นั้นๆ
คล้ายกับเว็บ thaicreate นี้ล่ะครับ ตอนเราทำการ edit กระทู้ครับ

ประมาณนี้ครับ [ผมอธิบายถูกต้องไหมครับ]
จะมีวิธีไหนทำได้บ้างครับ
รบกวนขอตัวอย่างหน่อยน่ะครับ
|
ประวัติการแก้ไข 2014-07-10 15:15:18 2014-07-10 15:20:15 2014-07-10 15:21:51
 |
 |
 |
 |
Date :
2014-07-10 15:13:17 |
By :
ลูกศิษย์ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|