 |
|
ติด Error คะ รบกวนพี่ๆที่อยู่ตอนนี้หน่อยคะ DBConnection และต้องการปุ่มลบข้อมูลด้วยคะ |
|
 |
|
|
 |
 |
|
Code (VB.NET)
strSQL = "DELETE FROM customer WHERE CustomerID = '"& lblCustomerID.Text &"' "
objCmd = New SqlCommand(strSQL, objConn)
objCmd.ExecuteNonQuery()
การลบข้อมูลผ่าน ADO.Net
|
 |
 |
 |
 |
Date :
2016-03-19 22:48:03 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้าให้แสดงข้อมูลใน DataGridView ลองแบบนี้ดูนะ 
Code (VB.NET)
Private Sub showdata()
sql = "SELECT * FROM products"
command.Parameters.Clear()
command.CommandText = sql
adapter.SelectCommand = command
adapter.Fill(dataSt, "products")
DataGridView1.DataSource = dataSt.Tables("products")
'-- เปลี่ยนข้อความบนส่วนหัวคอลัมน์ของ DataGridView ให้เป็นภาษาไทย // เผื่ออยากได้อะนะ
With DataGridView1
If .RowCount <> 0 Then
.Columns(0).HeaderText = "รหัสสินค้า"
.Columns(1).HeaderText = "รายการ"
.Columns(2).HeaderText = "จำนวน"
.Columns(0).Width = 120
.Columns(1).Width = 130
.Columns(2).Width = 50
End If
End With
End Sub
|
 |
 |
 |
 |
Date :
2016-03-21 08:25:14 |
By :
Catty |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
Private Function showdata(strSQL As String,column As String) As Datatable
Call DBConnection()
Dim dt As Datatable = Null
Try
Da = New SqlDataAdapter(strSQL , Conn)
Ds.Tables.Clear()
Da.Fill(Ds, column )
td = Ds.Tables(column)
Catch ex As Exception
End Try
return dt
End Sub
จะ Select Delete Update ก็ใช้ได้ครบครับ
|
 |
 |
 |
 |
Date :
2016-03-21 08:57:55 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เพราะมัน เปิดแล้วไม่เคยปิดไงครับ
แก้แบบบ้านๆ
Code (VB.NET)
Private Function showdata(strSQL As String,column As String) As Datatable
Dim cnn As SqlConnection = New SqlConnection(......) 'connetionString
Dim dt As Datatable = Null
Try
cnn.Open()
Da = New SqlDataAdapter(strSQL , cnn)
Ds.Tables.Clear()
Da.Fill(Ds, column )
td = Ds.Tables(column)
Catch ex As Exception
cnn.Close()
End Try
return dt
End Sub
cnn.Open()/cnn.Close() ใน Function Connection ทิ้งไว้ครับ
เพราะยังไงซะใช้เสร็จมันก็จะปิดเองอยู่แล้ว
|
 |
 |
 |
 |
Date :
2016-03-26 15:38:12 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|