 |
|
สอบถามเรื่อง Datagridview กับ Textbox ให้่ข้อมูลเปลียนตามเมื่ีอเราคลิกที่ Datagridview |
|
 |
|
|
 |
 |
|

รูปนี้คือตัวที่ใช้งานได้สมบูรณ์ พอเราคลิกที่บริเวณ Datagridview ข้อมูลที่ Textbox จะเลื่อนตามครับ
แต่.....................
- พอผมกด Save หรือ เพิ้มข้อมูล พอผมเพิ้่มเสร็จแล้ว ปัญหาก็คือพอผมคลิกที่ Datagridview ข้อมูลที่ Textbox มันไม่เลื่อนตามสะแล้ว
รบกวนช่วยดูหน่อยนะครับ นี้ Code ของปุ่้ม Save
Private Sub Btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnsave.Click
If StaffIDTextBox.Text = "" Or NameTextBox.Text = "" Or LnameTextBox.Text = "" Or AddressTextBox.Text = "" Or UsernameTextBox.Text = "" Or PasswordTextBox.Text = "" Or TelTextBox.Text = "" Or EmailTextBox.Text = "" Then
MsgBox("กรุณากรอกข้อมูลให้ครบทุกช่อง", MsgBoxStyle.Exclamation, "แจ้งเตือน")
Return
End If
Dim con As New SqlConnection(strcon)
If con.State = ConnectionState.Closed Then
Try
con.Open()
Catch ex As Exception
MsgBox("ไม่สามารถเชื่อมถานข้อมูลได้", MsgBoxStyle.Critical, "เตือน")
Return
End Try
End If
Try
Dim strselect As String = "insert into staff (StaffID,Name,Lname,Address,Username,Password,Tel,Email) values ('" + StaffIDTextBox.Text + "','" + NameTextBox.Text + "','" _
+ LnameTextBox.Text + "','" + AddressTextBox.Text + "','" + UsernameTextBox.Text + "','" + PasswordTextBox.Text + "','" + TelTextBox.Text + "','" + EmailTextBox.Text + "')"
Dim com As New SqlCommand
com.CommandType = CommandType.Text
com.CommandText = strselect 'เลือกคำสั่ง
com.Connection = con 'เปืดถานข้อมูล
com.ExecuteNonQuery() 'ประมวลผล
Dim da As New SqlDataAdapter("Select * from staff", con)
Dim ds As DataSet = New DataSet
da.Fill(ds, "staff")
StaffDataGridView.DataSource = ds.Tables("staff")
StaffDataGridView.Sort(StaffDataGridView.Columns(0), System.ComponentModel.ListSortDirection.Ascending)
MsgBox("บันทึกข้อมูลเรียบร้อย", MsgBoxStyle.Information, "เตือน")
Catch ex As Exception
End Try
End Sub
Tag : .NET, VS 2008 (.NET 3.x), VS 2010 (.NET 4.x)
|
|
 |
 |
 |
 |
Date :
2012-05-17 17:07:00 |
By :
warchag |
View :
1439 |
Reply :
4 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
หลังจากที่ Save เสร็จ ลอง Bind ข้อมูลใน DataGridView ใหม่ครับ 
|
 |
 |
 |
 |
Date :
2012-05-17 20:54:44 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณพีมากครับได้แล้ว
|
 |
 |
 |
 |
Date :
2012-05-18 15:39:30 |
By :
warchag |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เดาน่ะนั่น 
|
 |
 |
 |
 |
Date :
2012-05-18 16:12:21 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมเอาบรรทัดที่ 26 กับ 27 ออกไปครับ )
|
 |
 |
 |
 |
Date :
2012-05-18 16:43:28 |
By :
warchag |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|