1
我需要填充DataGridview多選擇 我想填充dataGridview通過此代碼,它的工作,但是當我鍵入 1,2,3它獲得正確的值,但是當我鍵入700它得到7不是700 當我鍵入1,2,3,10它得到1,2,3 所以我怎麼可以輸入1,2,3,10,700以及與這些數據填充的DataGridView 感謝通過多值填充DataGridView
Imports System.Data
Imports System.Data.OleDb
Imports System.Text
Public Class Form1
Public OLECON As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\SCHEDULES_DB.accdb;Jet OLEDB:Database [email protected];")
Dim dt As New DataTable
Dim da As New OleDbDataAdapter
Dim cmd As New OleDbCommand
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sb As New StringBuilder()
For Each fieldId As String In TextBox1.Text
sb.Append("'").Append(fieldId).Append("',")
Next
Dim fieldList As String = sb.ToString().TrimEnd(","c)
Dim SQLStr As String = "Select * from Tbl_Employee where EmpID in (" & fieldList & ") order by EmpID"
dt.Clear()
cmd.Parameters.Clear()
cmd.CommandText = SQLStr
cmd.Connection = OLECON
da.SelectCommand = cmd
da.Fill(dt)
DataGridView1.DataSource = dt
End Sub
End Class
100%右許多謝謝 –