Advertisement
eleazar05

Excel to Datagridview

Oct 17th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.16 KB | None | 0 0
  1. Try
  2.             For i As Integer = 0 To dt_data.RowCount - 3
  3.                 Dim meter_number As String
  4.                 meter_number = dt_data.Rows(i).Cells(3).Value
  5.                 Dim query As String = "Select * from customer where meter_num = @meter_num ORDER BY actrdngdt ASC"
  6.                 conn.Open()
  7.                 Dim command As New SqlCommand(query, conn)
  8.                 command.Parameters.AddWithValue("@meter_num", meter_number)
  9.                 Dim da As New SqlDataAdapter(command)
  10.                 Dim ds As New DataSet
  11.  
  12.  
  13.                 If i = dt_data.RowCount - 3 Then
  14.                     da.Fill(ds, "customer")
  15.                     dt_sample.DataSource = ds.Tables(0)
  16.                 End If
  17.  
  18.  
  19.  
  20.                 conn.Close()
  21.  
  22.             Next
  23.         Catch ex As SqlException
  24.             MsgBox(ex.Message, MsgBoxStyle.Critical, "SQL Error")
  25.         Catch ex As Exception
  26.             MsgBox(ex.Message, MsgBoxStyle.Critical, "General Error")
  27.             'End Try
  28.             'Catch ex As Exception
  29.             'MessageBox.Show(String.Format("Error: {0}", ex.Message), "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error)
  30.         End Try
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement