Private Sub showdata()
Dim strSelect As String
DataGridView1.DataBindings.Clear()
Call DBConnection()
Try
strSelect = "select*from products"
Da = New SqlDataAdapter(strSelect, Conn)
'เติมข้อมูลไปในออปเจ็กต์Dataset
Ds.Tables.Clear()
Da.Fill(Ds, "products")
DataGridView1.DataSource = Ds.Tables("products")
Catch ex As Exception
End Try
strSelect = "select*from products"
End Sub
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
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 ทิ้งไว้ครับ
เพราะยังไงซะใช้เสร็จมันก็จะปิดเองอยู่แล้ว