จาก code นี้อ่ะคับ ถ้าจะเปลี่ยนตัวแปร Dim dt As New DataTable
มาใช้แบบที่เป็น dataset แทน ต้องเอามาปรับยังไงคับ รบกวนแนะนำด้วยครับ Code (VB.NET)
Private Sub BindDataGrid()
Dim myConnection As SqlCeConnection
Dim dt As New DataTable
Dim Adapter As SqlCeDataAdapter
myConnection = New SqlCeConnection("Data Source =" _
+ (System.IO.Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly.GetName.CodeBase ) + "\AppDatabase1.sdf;"))
myConnection.Open()
Dim myCommand As SqlCeCommand = myConnection.CreateCommand()
myCommand.CommandText = "SELECT [id], [name], [email] FROM [mytable]"
myCommand.CommandType = CommandType.Text
Adapter = New SqlCeDataAdapter(myCommand)
Adapter.Fill(dt)
myConnection.Close()
Dim tableStyle As New DataGridTableStyle()
tableStyle.MappingName = dt.TableName
Dim column As New DataGridTextBoxColumn()
column.MappingName = "id"
column.HeaderText = "ID"
column.Width = 30
tableStyle.GridColumnStyles.Add(column)
column = New DataGridTextBoxColumn()
column.MappingName = "name"
column.HeaderText = "Name"
column.Width = 40
tableStyle.GridColumnStyles.Add(column)
column = New DataGridTextBoxColumn()
column.Width = 70
column.MappingName = "email"
column.HeaderText = "Email"
tableStyle.GridColumnStyles.Add(column)
Me.dgName.DataSource = dt
Me.dgName.TableStyles.Clear()
Me.dgName.TableStyles.Add(tableStyle)
dt = Nothing
End Sub
Tag : .NET, Oracle, WebService, VB.NET, VS 2008 (.NET 3.x)
คือผมลองตามคำแนะนำแล้ว ข้อมูลไม่ออกอ่ะคับ ออกเฉพาะ header row ของ datagrid
ที่ผมทำ คือ มีสองส่วน
ส่วนแรกคือ ผมสร้างเป็น service ไว้บน server Code (VB.NET)
<WebMethod()> _
Public Function GetLocation() As DataSet
SQLCmd = ""
SQLCmd = "select loc_id from dhlit.tbl_rtvloc where loc_status = 'ACTIVE' and loc_id not in (select loc_id from dhlit.tbl_rtvstock) order by loc_id"
CMD = New OracleCommand(SQLCmd, ConDB)
ADP = New OracleDataAdapter(CMD)
ConDB.Open()
ADP.Fill(DBSet, "Info")
ConDB.Close()
If CInt(DBSet.Tables(0).Rows.Count) > 0 Then
Return DBSet
Else
Return Nothing
End If
End Function
Public RTVService As New RTVService.Service1
Private Sub RTVMovetoDockDoor_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
BindDataGrid()
End Sub
Private Sub BindDataGrid()
Dim datatest As New DataSet
datatest = RTVService.GetLocation()
Dim tableStyle As New DataGridTableStyle()
tableStyle.MappingName = datatest.Tables("Info").TableName
Dim column As New DataGridTextBoxColumn()
column.MappingName = "loc_id"
column.HeaderText = "Location"
column.Width = 100
tableStyle.GridColumnStyles.Add(column)
'column = New DataGridTextBoxColumn()
'column.MappingName = "name"
'column.HeaderText = "Name"
'column.Width = 40
'tableStyle.GridColumnStyles.Add(column)
'column = New DataGridTextBoxColumn()
'column.Width = 70
'column.MappingName = "email"
'column.HeaderText = "Email"
'tableStyle.GridColumnStyles.Add(column)
Me.DataGrid1.DataSource = datatest.Tables(0)
Me.DataGrid1.TableStyles.Clear()
Me.DataGrid1.TableStyles.Add(tableStyle)
datatest = Nothing
End Sub