sub SetGrid()
Datagridview.Datasource =null
ds = BindDS()
With DataGridView1
.DataSource = ds.Tables("TableName")
.AutoGenerateColumns = False
End With
end sub
conn.Open()
cm = conn.CreateCommand()
With cm
.CommandText = "SELECT * FROM GoodsExport ORDER BY rec_no"
.CommandType = CommandType.Text
End With
da = New SqlDataAdapter(cm)
da.Fill(dt)
conn.Close()
DataGridView1.DataSource = dt
Private Sub showDatagridview1()
conn.Open()
cm = conn.CreateCommand()
With cm
.CommandText = "SELECT * FROM GoodsExport ORDER BY rec_no"
.CommandType = CommandType.Text
End With
da = New SqlDataAdapter(cm)
da.Fill(dt)
conn.Close()
DataGridView1.DataSource = dt
DataGridView1.Columns.Clear()
Dim col As DataGridViewTextBoxColumn
col = New DataGridViewTextBoxColumn()
With col
.DataPropertyName = "rec_no"
.HeaderText = " ลำดับ"
.Width = "100"
End With
DataGridView1.Columns.Add(col)
col = New DataGridViewTextBoxColumn()
With col
.DataPropertyName = "dates"
.HeaderText = " วันที่จำหน่าย"
.Width = "150"
End With
DataGridView1.Columns.Add(col)
col = New DataGridViewTextBoxColumn()
With col
.DataPropertyName = "goodsID"
.HeaderText = " รหัสครุภัณฑ์"
.Width = "150"
End With
DataGridView1.Columns.Add(col)
col = New DataGridViewTextBoxColumn()
With col
.DataPropertyName = "goodsName"
.HeaderText = " ชื่อ"
.Width = "150"
End With
DataGridView1.Columns.Add(col)
col = New DataGridViewTextBoxColumn()
With col
.DataPropertyName = "barcode"
.HeaderText = " บาร์โค้ด"
.Width = "150"
End With
DataGridView1.Columns.Add(col)
col = New DataGridViewTextBoxColumn()
With col
.DataPropertyName = "goodsModel"
.HeaderText = " ยี่ห้อ/รุ่น"
.Width = "150"
End With
DataGridView1.Columns.Add(col)
col = New DataGridViewTextBoxColumn()
With col
.DataPropertyName = "goodsDetail"
.HeaderText = " รายละเอียด"
.Width = "150"
End With
DataGridView1.Columns.Add(col)
col = New DataGridViewTextBoxColumn()
With col
.DataPropertyName = "room"
.HeaderText = " ห้อง"
.Width = "150"
End With
DataGridView1.Columns.Add(col)
col = New DataGridViewTextBoxColumn()
With col
.DataPropertyName = "amountExport"
.HeaderText = " จำนวนจำหน่าย"
.Width = "150"
End With
DataGridView1.Columns.Add(col)
End Sub 'โชว์ข้อมูลใน Datagridview1
If MessageBox.Show("กลับหน้าหลัก ใช่หรือไม่ ?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) = Windows.Forms.DialogResult.Yes Then
DataGridView1.DataSource.Clear()
Me.Close()
End If
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
DataGridView1.DataSource = Getdata("SELECT * FROM dbo.Company_Position", "Data Source=192.168.6.204,1433;Initial Catalog=BASE;User ID=LAMAKA.TOR;Password=*******").DefaultView()
End Sub
Function Getdata(sql As String, connstring As String) As DataTable
Dim ds As System.Data.DataSet = New DataSet()
Dim adapter As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter(sql, connstring)
adapter.Fill(ds)
Return ds.Tables(0)
End Function
แบบนี้พอได้ป่ะครับผมไม่ค่อยเหมือนใครชอบ return function เอา
ประเด็นคือแค่อยาก รีเฟชดาต้าเฉยๆรึอย่างอื่นด้วยครับ
Public Function BindDataExport() As DataSet
strcon = "select * from GoodsExport order by rec_no"
ds = New DataSet
da = New SqlDataAdapter(strcon, conn)
da.Fill(ds, "GoodsExport")
Return ds
End Function
Public Function BindDataExport() As DataSet
strcon = "select * from GoodsExport order by rec_no"
ds = New DataSet
da = New SqlDataAdapter(strcon, conn)
da.Fill(ds, "GoodsExport")
Return ds
End Function
Public Function BindDataExport() As DataTable
strcon = "select * from GoodsExport order by rec_no"
ds = New DataSet
da = New SqlDataAdapter(strcon, conn)
da.Fill(ds, "GoodsExport")
Return ds.Tables(0)
End Function
If MessageBox.Show("กลับหน้าหลัก ใช่หรือไม่ ?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) = Windows.Forms.DialogResult.Yes Then
DataGridView1.DataSource.Clear()
Me.Dispose()
Me.Close()
End If