|
 |
|
สอบถามต้องการให้ เวลาแก้ไขรายการเสร็จแล้วเมื่อกด Save ให้หน้า Gridview เปลี่ยนแสดงที่เราแก้ไขเลยครับ |
|
 |
|
|
 |
 |
|
สอบถามต้องการให้ เวลาแก้ไขรายการเสร็จแล้วเมื่อกด Save ให้หน้า Gridview เปลี่ยนแสดงที่เราแก้ไขเลยครับ ทํายังไง
Code (C#)
public void get_list_Supplier()
{
string status;
adap = new MySqlDataAdapter("SELECT * FROM supplier", con);
DataTable dt = new DataTable();
adap.Fill(dt);
dataGridView1.Rows.Clear();
adap.Update(dt);
// Initialize basic DataGridView properties.
//dataGridView1.Dock = DockStyle.Fill;
dataGridView1.BackgroundColor = Color.LightGray;
dataGridView1.BorderStyle = BorderStyle.Fixed3D;
dataGridView1.AllowUserToAddRows = false;
foreach (DataRow items in dt.Rows)
{
int n = dataGridView1.Rows.Add();
dataGridView1.Rows[n].HeaderCell.Value = (n + 1).ToString();
dataGridView1.Rows[n].Cells[0].Value = items["id_supplier"].ToString();
dataGridView1.Rows[n].Cells[1].Value = items["supplier_code"].ToString();
dataGridView1.Rows[n].Cells[2].Value = items["company_name"].ToString();
dataGridView1.Rows[n].Cells[3].Value = items["contact_fname"].ToString();
dataGridView1.Rows[n].Cells[4].Value = items["contact_lname"].ToString();
dataGridView1.Rows[n].Cells[5].Value = items["address"].ToString();
dataGridView1.Rows[n].Cells[6].Value = items["phone"].ToString();
dataGridView1.Rows[n].Cells[7].Value = items["moblie"].ToString();
dataGridView1.Rows[n].Cells[8].Value = items["fax"].ToString();
dataGridView1.Rows[n].Cells[9].Value = items["email"].ToString();
if (items["status"].ToString() == "1")
{
status = "ใช้งาน";
}
else
{
status = "ไม่ใช้งาน";
}
dataGridView1.Rows[n].Cells[10].Value = status;
}
}
Code (C#)
private void save_Click(object sender, EventArgs e)
{
if (supplier_code.Text == "")
{
errorProvider1.SetError(supplier_code, "กรุณากรอกข้อมูล");
}
else if (company_name.Text == "")
{
errorProvider1.Clear();
errorProvider1.SetError(company_name, "กรุณากรอกข้อมูล");
}
else if (contact_f.Text == "")
{
errorProvider1.Clear();
errorProvider1.SetError(contact_f, "กรุณากรอกข้อมูล");
}
else if (contact_l.Text == "")
{
errorProvider1.Clear();
errorProvider1.SetError(contact_l, "กรุณากรอกข้อมูล");
}
else if (contact_title.Text == "")
{
errorProvider1.Clear();
errorProvider1.SetError(contact_title, "กรุณากรอกข้อมูล");
}
else if (address.Text == "")
{
errorProvider1.Clear();
errorProvider1.SetError(address, "กรุณากรอกข้อมูล");
}
else if (moblie.Text == "")
{
errorProvider1.Clear();
errorProvider1.SetError(moblie, "กรุณากรอกข้อมูล");
}
else
{
errorProvider1.Clear();
DateTime dt = DateTime.Now;
cmd = con.CreateCommand();
cmd.CommandText = "INSERT INTO supplier(supplier_code, company_name, contact_fname, contact_lname, ";
cmd.CommandText += "contact_title, address, phone, moblie, fax, email, url, status, create_date) VALUES ";
cmd.CommandText += "('" + supplier_code.Text + "', '" + company_name.Text + "', '" + contact_f.Text + "', '" + contact_l.Text + "', ";
cmd.CommandText += "'" + contact_title.Text + "', '" + address.Text + "', '" + phone.Text + "', '" + moblie.Text + "', ";
cmd.CommandText += "'" + fax.Text + "', '" + email.Text + "', '" + website.Text + "', '1', '" + dt.ToString("yyyy-MM-dd") + "')";
int result = cmd.ExecuteNonQuery();
if (result == 1)
{
MessageBox.Show("บันทึกข้อมูลเรียบร้อย");
}
else
{
MessageBox.Show("ไม่สามารถบันทึกข้อมูลได้");
}
list_supplier list = new list_supplier();
list.get_list_Supplier();
}
}
Tag : .NET

|
ประวัติการแก้ไข 2014-06-12 21:28:59
|
 |
 |
 |
 |
Date :
2014-06-12 21:03:25 |
By :
kenghockey |
View :
1068 |
Reply :
5 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
หลังจาก INSERT แล้วผมให้มันไปเรียก list.get_list_Supplier(); อีกครั้งเพื่อจะได้เห็นข้อมูลที่ถูก Insert ไปล่าสุด แต่มันไม่มีอะไรโผล่มาเลยครับ ไม่ทราบตรงนี้ผมเขียนถูกหรือเปล่าครับ แล้วเกี่ยวไปไหมครับที list.get_list_Supplier(); ผมใช้เป็น foreach ครับ
|
 |
 |
 |
 |
Date :
2014-06-13 08:58:43 |
By :
kenghockey |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่มีให้ทราบเลยหรอครับ
|
 |
 |
 |
 |
Date :
2014-06-15 08:00:44 |
By :
kenghockey |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เรียกเพื่อ Bind ข้อมูลใหม่ถูกแล้วครับ แต่ไม่ลอง Debug ดูล่ะครับ ว่าทำงานถูกหรือไม่
|
 |
 |
 |
 |
Date :
2014-06-15 11:23:03 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองแล้วครับ แต่ไม่ได้ผมเลยลองสร้างปุ่ม รีเฟรชขึ้นมา โดยถ้ากดปุ่มก็จะเรียก bind ใหม่อีกทีครับมันก็ใช้ได้นะครับ
แต่แปลกทําไมเวลาแก้ไข หรือเซฟมัน เรียกแล้วไม่ได้ผล
|
 |
 |
 |
 |
Date :
2014-06-15 14:59:53 |
By :
kenghockey |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จากที่ลองทําดูนะครับ
ถ้าผมเขียนฟอร์มแค่ฟอร์มเดียวแล้ว Insert มันจะโชว์ใน Datagridview เลยครับ
แต่พอโชว์ Datagridview ฟอร์มนึงแล้วก็ ไป Insert อีกฟอร์มนึง มันจะไม่โชว์ให้เลยครับ มีทางแก่ไขไหมครับ
|
 |
 |
 |
 |
Date :
2014-06-16 18:27:03 |
By :
kenghockey |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|