你正在混合一些不适合的线。
'Get data from a sqlserver and fill a datatable with those data
Dim connectionString = _conn_Test
Dim table = New DataTable
dataAdapter = New SqlDataAdapter(selectCommand,connectionString)
dataAdapter.Fill(table)
所以现在您有一个表中填充了来自SelectCommand查询的所有数据的表。
此表您可以用作ListBoxes DataGridView的DataSource,或者其他所有其他功能都可以使用DataSource。
另一种方式TIO创建数据源是
Dim bindingSource1 As BindingSource
bindingSource1.DataSource = table
此,您也可以使用填充DataGridViews或listboxes等。
'Bild a new table as datasource
Dim table = New DataTable
'Add new Colmuns to the Table
table.Columns.Add("cie_code", GetType(System.String))
table.Columns.Add("cie_nom", GetType(System.String))
'Add 1 new row can be encklosed in a for loop
Dim newrow as As DataRo = table.NewRow()
newrow ("cie_code") = "Youtext1"
newrow ("cie_nom") = "Yourtext2"
table.Rows.Add(newrow)
'Change 1 Column of of all rows
For i as Integer = 0 To table.Rows.Count - 1
table.Rows(i).Item("cie_nom") = "newtext"
Next
'Define new elements to demonstrate what to do with datasouurces
Dim ListBox1 As ListBox
Dim bindingSource2 As BindingSource
This would sow a Listbox with one element newtext
bindingSource2.DataSource = table
listBox1.DataSource = bindingSource2
listBox1.DisplayMember = "cie_nom"
锅中的最后一件事是
Dim commandBuilder = New SqlCommandBuilder(dataAdapter)
您可以通过在链接中执行SQL命令更改SQL Server中的数据
https://docs.microsoft.com/de-de/dotnet/api/system.data.sqlclient.sqldataadapter.insertcommand?view=netframework-4.8
您可以在其中构建您自己的更新,插入和/或删除命令以操纵SQL Server中的数据。
或者您操作填充桌子中的数据,让DOT网进行工作。通过以下行为
Dim commandBuilder1 = New SqlCommandBuilder(dataAdapter)
'this next works with commandbuilder or your own sql ,commands
dataAdapter.Update(table)
将来试图保持您的问题专注于一个问题。
当您想在搜索引擎中输入某些内容时,您可以在开始时用VB网进行纯文本问题,并查看它需要您的位置。通常在这里或Microsoft Docs和一些其他页面博客等,您可能会发现自己尝试的灵感。
所示的示例通常很容易,因此可以正确解释它。复杂你必须弄清楚自己或你很幸运,别人已经尝试过它并成功了。
我希望这有助于一点点