 |
|
[.NET]
C# ช่วยด้วยคับ คือผมบันทึกข้อมูลลงไปใน Sql Server ไม่ได้คับ ช่วยผมหน่อยคับ |
|
 |
|
|
 |
 |
|
คือบันทึกครั้งแรกผมบันทึกได้คับ พอจะบันทึกอีกครั้งมันไม่ได้อ่ะคับ

Code (C#)
01. private void Save()
02. {
03. Connect objconn = new Connect();
04. SqlCommand sqlCMD;
05. SqlDataReader sqlDR;
06.
07.
08. objconn.Conn();
09. {
10. string strSQL;
11. strSQL = "Select * from Table_Agent order by Agent_ID" ;
12. sqlCMD = new SqlCommand(strSQL, objconn.conns);
13. sqlDR = sqlCMD.ExecuteReader();
14. if (sqlDR.Read())
15. {
16. strSQL = "Update Table_Agent set Agent_Name = '" + textBox10.Text + "'" ;
17. strSQL += "Agent_Store = '" + textBox9.Text + "'" ;
18. strSQL += "Agent_HouseNo = '" + textBox3.Text + "'" ;
19. strSQL += "Agent_Village = '" + textBox4.Text + "'" ;
20. strSQL += "Agent_District = '" + textBox5.Text + "'" ;
21. strSQL += "Agent_Prefecture = '" + textBox6.Text + "'" ;
22. strSQL += "Agent_Province = '" + textBox7.Text + "'" ;
23. strSQL += "Agent_PostalCode = '" + maskedTextBox1.Text + "'" ;
24. strSQL += "Agent_Phone = '" + maskedTextBox2.Text + "'" ;
25. strSQL += "where Agent_ID = '" + textBox1.Text + "'" ;
26. }
27. else
28. {
29. strSQL = "Insert into Table_Agent(Agent_ID,Agent_Name,Agent_Store,Agent_HouseNo, Agent_Village,Agent_District,Agent_Prefecture,Agent_Province, Agent_PostalCode,Agent_Phone)" ;
30. strSQL += "Values('" + textBox1.Text + "' ,'" + textBox10.Text + "', '" + textBox9.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "' ,'" + textBox7.Text + "','" + maskedTextBox1.Text + "','" + maskedTextBox2.Text + "')" ;
31. }
32. sqlDR.Close();
33. sqlCMD = new SqlCommand(strSQL, objconn.conns);
34. int numRec = sqlCMD.ExecuteNonQuery();
35. if (numRec > 0)
36. {
37. MessageBox.Show( "บันทึกข้อมูลเรียบร้อยแล้ว" );
38. }
39. else
40. {
41. MessageBox.Show( "ไม่สามารถบันทึกข้อมูลได้" );
42. }
43. }
44. }
45.
46. private void button12_Click( object sender, EventArgs e)
47. {
48. DialogResult strDel;
49. strDel = MessageBox.Show( "คุณต้องการลบข้อมมูลใช่หรือไม่ ?" , "ยืนยันการลบ" , MessageBoxButtons.YesNo, MessageBoxIcon.Question);
50. if (strDel == DialogResult.OK)
51. {
52. Dele();
53. }
54. showAgent();
55. }
Tag : Ms SQL Server 2012, C#, C
|
|
 |
 |
 |
 |
Date :
2013-07-31 13:18:22 |
By :
coutiho |
View :
2978 |
Reply :
24 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
,
|
ประวัติการแก้ไข 2013-08-01 00:21:06 2013-08-01 00:21:26
 |
 |
 |
 |
Date :
2013-08-01 00:20:36 |
By :
01000010 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอาใส่ตรงไหนหรอคับ ยัง งงๆอยู่เลยคับ
|
 |
 |
 |
 |
Date :
2013-08-01 20:56:28 |
By :
coutiho |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
debug แล้วเอา code ออกมาดูครับ ตรง Update เครื่องหมาย (,) ขั้นระหว่าง column หายไปหมดเลย
|
 |
 |
 |
 |
Date :
2013-08-01 21:39:20 |
By :
mungkorn001 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
กระจางแล้วคับ ขอบคุณมากคับ
|
 |
 |
 |
 |
Date :
2013-08-02 07:59:52 |
By :
coutiho |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คือใส่แล้วคับ มันบอกว่า "ไม่สามารถบันทึกข้อมูลได้" คับ
|
 |
 |
 |
 |
Date :
2013-08-04 11:00:38 |
By :
coutiho |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (C#)
01. strSQL = "Update Table_Agent set Agent_Name = '" + textBox10.Text + "'," ;
02. strSQL += "Agent_Store = '" + textBox9.Text + "'," ;
03. strSQL += "Agent_HouseNo = '" + textBox3.Text + "'," ;
04. strSQL += "Agent_Village = '" + textBox4.Text + "'," ;
05. strSQL += "Agent_District = '" + textBox5.Text + "'," ;
06. strSQL += "Agent_Prefecture = '" + textBox6.Text + "'," ;
07. strSQL += "Agent_Province = '" + textBox7.Text + "'," ;
08. strSQL += "Agent_PostalCode = '" + maskedTextBox1.Text + "'," ;
09. strSQL += "Agent_Phone = '" + maskedTextBox2.Text + "'," ;
แถวสุดท้ายนี้ไม่ใส่ (,) น่ะคับ
Code (C#)
1. strSQL += "where Agent_ID = '" + textBox1.Text + "'" ;
|
 |
 |
 |
 |
Date :
2013-08-04 19:17:41 |
By :
keooudone |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (C#)
01. private void Save()
02. {
03. Connect objconn = new Connect();
04. SqlCommand sqlCMD;
05. SqlDataReader sqlDR;
06.
07.
08. objconn.Conn();
09. {
10. string strSQL;
11. strSQL = "Select * from Table_Agent order by Agent_ID" ;
12. sqlCMD = new SqlCommand(strSQL, objconn.conns);
13. sqlDR = sqlCMD.ExecuteReader();
14. if (sqlDR.Read())
15. {
16. strSQL = "Update Table_Agent set Agent_Name = '" + textBox10.Text + "'" ;
17. strSQL += ",Agent_Store = '" + textBox9.Text + "'" ;
18. strSQL += ",Agent_HouseNo = '" + textBox3.Text + "'" ;
19. strSQL += ",Agent_Village = '" + textBox4.Text + "'" ;
20. strSQL += ",Agent_District = '" + textBox5.Text + "'" ;
21. strSQL += ",Agent_Prefecture = '" + textBox6.Text + "'" ;
22. strSQL += ",Agent_Province = '" + textBox7.Text + "'" ;
23. strSQL += ",Agent_PostalCode = '" + maskedTextBox1.Text + "'" ;
24. strSQL += ",Agent_Phone = '" + maskedTextBox2.Text + "'" ;
25. strSQL += "where Agent_ID = '" + textBox1.Text + "'" ;
26. }
27. else
28. {
29. strSQL = "Insert into Table_Agent(Agent_ID,Agent_Name,Agent_Store,Agent_HouseNo, Agent_Village,Agent_District,Agent_Prefecture,Agent_Province, Agent_PostalCode,Agent_Phone)" ;
30. strSQL += "Values('" + textBox1.Text + "' ,'" + textBox10.Text + "', '" + textBox9.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "' ,'" + textBox7.Text + "','" + maskedTextBox1.Text + "','" + maskedTextBox2.Text + "')" ;
31. }
32. sqlDR.Close();
33. sqlCMD = new SqlCommand(strSQL, objconn.conns);
34. int numRec = sqlCMD.ExecuteNonQuery();
35. if (numRec > 0)
36. {
37. MessageBox.Show( "บันทึกข้อมูลเรียบร้อยแล้ว" );
38. }
39. else
40. {
41. MessageBox.Show( "ไม่สามารถบันทึกข้อมูลได้" );
42. }
43. }
44. }
45.
46. private void button12_Click( object sender, EventArgs e)
47. {
48. DialogResult strDel;
49. strDel = MessageBox.Show( "คุณต้องการลบข้อมมูลใช่หรือไม่ ?" , "ยืนยันการลบ" , MessageBoxButtons.YesNo, MessageBoxIcon.Question);
50. if (strDel == DialogResult.OK)
51. {
52. Dele();
53. }
54. showAgent();
55. }
แต่มันก็ไม่ได้อ่ะคับ ปวดหัวมากๆๆๆๆๆๆๆๆๆๆๆๆๆๆ
|
 |
 |
 |
 |
Date :
2013-08-07 10:51:19 |
By :
coutiho |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมงงตั้งแต่บรรทัดนี้แล้วครับ
Code (C#)

|
 |
 |
 |
 |
Date :
2013-08-07 11:11:50 |
By :
01000010 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (C#)
งง ตรงนี้เหมือนกันครับ
ว่าแต่สรุปแล้ว จะทำอะไรในลักษณะไหนครับ
|
 |
 |
 |
 |
Date :
2013-08-07 12:11:44 |
By :
CPU4Core |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมจะบันทึกข้อมูลลงฐานข้อมูล แล้วมันบันทึกไม่ได้คับ มันโชว์
MessageBox.Show("ไม่สามารถบันทึกข้อมูลได้")
|
 |
 |
 |
 |
Date :
2013-08-10 11:07:14 |
By :
coutiho |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่ Error อะไรเลยคับ
|
 |
 |
 |
 |
Date :
2013-09-14 19:11:05 |
By :
coutiho |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
int numRec = sqlCMD.ExecuteNonQuery();
if (numRec > 0)
ตรงนี้ผมเข้าใจว่า ถ้า ExecuteNonQuery() สำเร็จ กำหนดค่าให้ numRec = 1
เพื่อให้ขึ้น PopUp เตือน
ลองเปลี่ยนดีไหมครับ จะได้รู้ว่า error ของระบบเป็นอะไร
Code (C#)
01. string errMsg = string .Empty;
02. bool success = false ;
03. try
04. {
05. sqlCMD.ExecuteNonQuery();
06. success = true ;
07. }
08. catch (Exception ex)
09. {
10. errMsg = ex.Message;
11. }
12. finally
13. {
14. if (success)
15. {
16. MessageBox.Show( "บันทึกข้อมูลเรียบร้อยแล้ว" );
17. }
18. else
19. {
20. MessageBox.Show(errMsg);
21. }
22. }
|
ประวัติการแก้ไข 2013-09-14 19:58:55 2013-09-14 20:00:00
 |
 |
 |
 |
Date :
2013-09-14 19:58:14 |
By :
Aod47 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (C#)
01. strSQL = "Select * from Table_Agent order by Agent_ID" ; <<<
02. sqlCMD = new SqlCommand(strSQL, objconn.conns);
03. sqlDR = sqlCMD.ExecuteReader();
04. if (sqlDR.Read())
05. {
06. update
07. }
08. else
09. {
10. insert
11. }
เมื่อไรจะเข้า else อะครับ หรือผมเข้าใจผิด
|
 |
 |
 |
 |
Date :
2013-09-24 09:49:19 |
By :
ghosting789 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
รบกวนหน่อยน่ะคร้า ปุ่มบันทึกข้อมูลคร้า (มันบันทึกไม่ได้อ่ะคร้า ไม่ลงฐานข้อมูล)
         
Code (C#)
01. using System;
02. using System.Collections.Generic;
03. using System.ComponentModel;
04. using System.Data;
05. using System.Drawing;
06. using System.Linq;
07. using System.Text;
08. using System.Threading.Tasks;
09. using System.Windows.Forms;
10. using System.Data.SqlClient;
11.
12. namespace WindowsFormsApplication4
13. {
14. public partial class Form1 : Form
15. {
16. public Form1()
17. {
18. InitializeComponent();
19. }
20.
21. SqlConnection Conn;
22.
23. SqlCommand Com;
24. SqlDataReader dr;
25.
26.
27.
28. StringBuilder sb = new StringBuilder();
29.
30. private void Form1_Load( object sender, EventArgs e)
31. {
32.
33. string strConn;
34.
35. strConn = "Data Source=./SQLEXPRESS; Initial Catalog=lam; Integrated Security=True" ;
36.
37. Conn = new SqlConnection();
38.
39. if (Conn.State == ConnectionState.Open)
40.
41. {
42.
43. Conn.Close();
44.
45. }
46.
47. Conn.ConnectionString = strConn;
48.
49. Conn.Open();
50.
51. }
52.
53. private void button2_Click( object sender, EventArgs e)
54. {
55.
56. if (tetID.Text.Trim() == "" )
57. {
58.
59. MessageBox.Show( "กรุณาป้อนรหัสลูกค้า !!!" , "ข้อผิดพลาด" , MessageBoxButtons.OK, MessageBoxIcon.Exclamation );
60. tetID.Focus();
61. return ;
62.
63. }
64. sb.Remove(0, sb.Length);
65.
66. sb.Append( "INSERT INTO lam(ID,name,lastname)VALUES(@txtID,@txtname,@tetlastname)" );
67.
68. sb.Append( " VALUES (@ma,@lamDataSet1)" );
69.
70. string sqlSave = sb.ToString();
71.
72. Com.CommandType = CommandType.Text;
73. Com.CommandType = CommandType.Text;
74. Com.CommandType = CommandType.Text;
75. Com.CommandType = CommandType.Text;
76. Com.CommandText = sqlSave;
77. Com.Connection = Conn;
78.
79.
80. Com.Parameters.Clear();
81. Com.Parameters.Add( "@txtID" , SqlDbType.NChar).Value = tetID.Text.Trim();
82. Com.Parameters.Add( "@txtname" , SqlDbType.NChar).Value = tetname.Text.Trim();
83. Com.Parameters.Add( "@lastname" , SqlDbType.NChar).Value = tetlastname.Text.Trim();
84. Com.ExecuteNonQuery();
85. MessageBox.Show( "บันทึกข้อมูลเรียบร้อยแล้ว" , "รายงานผล" , MessageBoxButtons.OK, MessageBoxIcon.Information);
86. }
87. }
88.
89.
90.
91. }
|
 |
 |
 |
 |
Date :
2013-11-21 14:29:29 |
By :
ด้าดา |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
รบกวนหน่อยน่ะคร้า ปุ่มบันทึกข้อมูลคร้า (มันบันทึกไม่ได้อ่ะคร้า ไม่ลงฐานข้อมูล)
         
Code (C#)
01. using System;
02. using System.Collections.Generic;
03. using System.ComponentModel;
04. using System.Data;
05. using System.Drawing;
06. using System.Linq;
07. using System.Text;
08. using System.Threading.Tasks;
09. using System.Windows.Forms;
10. using System.Data.SqlClient;
11.
12. namespace WindowsFormsApplication4
13. {
14. public partial class Form1 : Form
15. {
16. public Form1()
17. {
18. InitializeComponent();
19. }
20.
21. SqlConnection Conn;
22.
23. SqlCommand Com;
24. SqlDataReader dr;
25.
26.
27.
28. StringBuilder sb = new StringBuilder();
29.
30. private void Form1_Load( object sender, EventArgs e)
31. {
32.
33. string strConn;
34.
35. strConn = "Data Source=./SQLEXPRESS; Initial Catalog=lam; Integrated Security=True" ;
36.
37. Conn = new SqlConnection();
38.
39. if (Conn.State == ConnectionState.Open)
40.
41. {
42.
43. Conn.Close();
44.
45. }
46.
47. Conn.ConnectionString = strConn;
48.
49. Conn.Open();
50.
51. }
52.
53. private void button2_Click( object sender, EventArgs e)
54. {
55.
56. if (tetID.Text.Trim() == "" )
57. {
58.
59. MessageBox.Show( "กรุณาป้อนรหัสลูกค้า !!!" , "ข้อผิดพลาด" , MessageBoxButtons.OK, MessageBoxIcon.Exclamation );
60. tetID.Focus();
61. return ;
62.
63. }
64. sb.Remove(0, sb.Length);
65.
66. sb.Append( "INSERT INTO lam(ID,name,lastname)VALUES(@txtID,@txtname,@tetlastname)" );
67.
68. sb.Append( " VALUES (@ma,@lamDataSet1)" );
69.
70. string sqlSave = sb.ToString();
71.
72. Com.CommandType = CommandType.Text;
73. Com.CommandType = CommandType.Text;
74. Com.CommandType = CommandType.Text;
75. Com.CommandType = CommandType.Text;
76. Com.CommandText = sqlSave;
77. Com.Connection = Conn;
78.
79.
80. Com.Parameters.Clear();
81. Com.Parameters.Add( "@txtID" , SqlDbType.NChar).Value = tetID.Text.Trim();
82. Com.Parameters.Add( "@txtname" , SqlDbType.NChar).Value = tetname.Text.Trim();
83. Com.Parameters.Add( "@lastname" , SqlDbType.NChar).Value = tetlastname.Text.Trim();
84. Com.ExecuteNonQuery();
85. MessageBox.Show( "บันทึกข้อมูลเรียบร้อยแล้ว" , "รายงานผล" , MessageBoxButtons.OK, MessageBoxIcon.Information);
86. }
87. }
88.
89.
90.
91. }
|
 |
 |
 |
 |
Date :
2013-11-21 14:29:55 |
By :
ด้าดา |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองดูตรงนี้ก่อน

ถ้าไม่ได้ ผมลองเอาโค๊ดเขียนในแบบผมดู
Code (C#)
01. SqlConnection Conn = new sqlconnection( "Data Source=./SQLEXPRESS; Initial Catalog=lam; Integrated Security=True" );
02.
03. private void Form1_Load( object sender, EventArgs e)
04. {
05.
06.
07. if (Conn.State == ConnectionState.Open)
08.
09. {
10.
11. Conn.Close();
12.
13. }
14.
15. }
16.
17. private void button2_Click( object sender, EventArgs e)
18. {
19.
20. if (tetID.Text.Trim() == "" )
21. {
22.
23. MessageBox.Show( "กรุณาป้อนรหัสลูกค้า !!!" , "ข้อผิดพลาด" , MessageBoxButtons.OK, MessageBoxIcon.Exclamation );
24. tetID.Focus();
25. return ;
26.
27. }
28. try
29. {
30. conn.open();
31. string sql = "INSERT INTO lam(ID,name,lastname)VALUES(@txtID,@txtname,@tetlastname)" ;
32. sqlcommand cmd = new sqlcommand (sql,conn)
33. string texID = tetID.Text.Trim();
34. string texName = tetname.Text.Trim();
35. string texLastName = tetlastname.Text.Trim();
36. cmd.Parameters.Add( new SqlParameter( "@txtID" , texID));
37. cmd.Parameters.Add( new SqlParameter( "@txtname" , texName));
38. cmd.Parameters.Add( new SqlParameter( "@txtlastname" , texLastName));
39. SqlDataReader reader = cmd.ExecuteReader();
40.
41. MessageBox.Show( "บันทึกข้อมูลเรียบร้อยแล้ว" , "รายงานผล" , MessageBoxButtons.OK, MessageBoxIcon.Information);
42. conn.close();
43. }
44. catch
45. {
46. MessageBox.show ( "Error" );
47. }
48. }
|
 |
 |
 |
 |
Date :
2013-11-25 00:59:55 |
By :
Laser.Wz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
     ขอบคุณมากๆเลยค่ะ
|
 |
 |
 |
 |
Date :
2013-11-25 11:41:08 |
By :
ด้าดา |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
         
รบกวนอีกทีน่ะ ค่ะ มัน Error ตรง SqlConnection conn; น่ะค่ะ แก้แล้วก็เหมือนเดิม ช่วยหน่อยน่ะค่ะ ขอบคุณมากค่ะ
SqlConnection conn;
StringBuilder sb = new StringBuilder();
SqlConnection Conn = new SqlConnection ("Data Source=./SQLEXPRESS; Initial Catalog=lam; Integrated Security=True");
private void Form1_Load(object sender, EventArgs e)
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
}
private void button2_Click(object sender, EventArgs e)
{
if (tetID.Text.Trim() == "")
{
MessageBox.Show("กรุณาป้อนรหัสลูกค้า !!!", "ข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Exclamation );
tetID.Focus();
return;
}
try
{
conn.Open();
string sql = "INSERT INTO lam (ID,name,lastname)VALUES(@tetID,@tetname,@tetlastname)";
SqlCommand cmd = new SqlCommand(sql, conn);
string texID = tetID.Text.Trim();
string texName = tetname.Text.Trim();
string texlastName = tetlastname.Text.Trim();
cmd.Parameters.Add(new SqlParameter("@tetID", tetID));
cmd.Parameters.Add(new SqlParameter("@tetname", tetname));
cmd.Parameters.Add(new SqlParameter("@tetlastname", tetlastname));
SqlDataReader reader = cmd.ExecuteReader();
MessageBox.Show("บันทึกข้อมูลเรียบร้อยแล้ว", "รายงานผล", MessageBoxButtons.OK, MessageBoxIcon.Information);
Conn.Close();
}
catch
{
MessageBox.Show ("Error");
}
}
}
}
|
 |
 |
 |
 |
Date :
2013-11-26 10:09:40 |
By :
ด้าดา |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
      
ทำได้แล้วน่ะค่ะ ลงฐานข้อมูลแล้วค่ะ ขอบคุณมากๆน่ะค่ะ (โอกาศหน้าจะมารบกวนอีกน่ะค่ะ)     
|
 |
 |
 |
 |
Date :
2013-11-26 12:32:24 |
By :
ด้าดา |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
     
แก้ไขไม่ได้อ่ะค่ะ รบกวนช่วยดูให้หน่อยนะค่ะ ขอบคุณมากค่ะ  :l
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SqlConnection conn;
SqlCommand comm;
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
long Affect = 0; // ประกาศตัวแปรในการเช็คว่ามีข้อมูลหรือไม่ หรือ จะประยุกต์ เป็นการแบบ บูลีน ก้ได้ แล้ว Return ค่ามาค่ะ
string sqlEdit;
//SqlCommand comEdit = new SqlCommand();
if (MessageBox.Show("คุณต้องการแก้ไขข้อมูลสมาชิก ใช่หรือไม่?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
sqlEdit = "UPDATE lam ";
sqlEdit += "ID='" + tetID.Text + "',";
sqlEdit += " name='" + tetname.Text + "',";
sqlEdit += " lastname='" + tetlastname.Text + "',";
try
{
comm.CommandType = CommandType.Text;
comm.CommandText = sqlEdit;
comm.Connection = conn;
Affect = comm.ExecuteNonQuery();
}
catch (Exception errToEdit)
{
MessageBox.Show("ไม่สามารถแก้ไขได้ เนื่องจาก " + errToEdit.Message, "เกิดข้อผิดพลาด");
}
if (Affect == 0) //กรณีไม่พบ
{
//MessageBox.Show("ไม่พบข้อมูล หรือ ไม่มีข้อมูลในระบบ", "ข้อความจากระบบ");
}
if (Affect > 0) //กรณีพบ
{
tetID.Text = "";
tetname.Text = "";
tetlastname.Text = "";
MessageBox.Show("แก้ไขข้อมูลพนักงาน เรียบร้อยแล้ว !!!", "ผลการทำงาน");
}
}
}
}
}
|
 |
 |
 |
 |
Date :
2013-12-02 10:47:36 |
By :
ด้าดา |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|