当我从Excel打开文件并将其显示在dt_data
中时,我试图这样做,我想选择数据库中是否存在dt_data
中的特定列并显示结果在另一个datagridview
dt_sample
中。
我已经开始工作了,但是问题是仅显示dt_data
中的第一行。
Try
For i As Integer = 0 To dt_data.RowCount - 3
Dim meter_number As String
meter_number = dt_data.Rows(i).Cells(3).Value
Dim query As String = "Select * from customer where meter_num = @meter_num"
conn.Open()
Dim command As New SqlCommand(query, conn)
command.Parameters.AddWithValue("@meter_num", meter_number)
Dim da As New SqlDataAdapter(command)
Dim ds As New DataSet
da.Fill(ds, "customer")
dt_sample.DataSource = ds.Tables(i)
conn.Close()
Next
Catch ex As SqlException
MsgBox(ex.Message, MsgBoxStyle.Critical, "SQL Error")
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "General Error")
'End Try
'Catch ex As Exception
'MessageBox.Show(String.Format("Error: {0}", ex.Message), "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error)
End Try