i want to display data to DataGridView using DataSet which is didn't work DataTable instead,,thanks hers my code!!
Using DataSet
Dim Sql As String
Dim Command As New SqlCommand... See More
Dim Adapter As New SqlDataAdapter
Dim Sqlconn As New SqlConnection
Dim ds As New DataSet
Sql = "Sql Statement here;"
Sqlconn.ConnectionString = connection
Try
Command.Connection = Sqlconn
Command.CommandText = Sql
Adapter.SelectCommand = Command
Adapter.Fill(ds)
If dt.Tables(0).Rows.Count() > 0 Then
DataGridView1 = dt
Else
DataGridView1 = Nothing
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
Using DataTable then its work
Dim Sql As String
Dim Command As New SqlCommand
Dim Adapter As New SqlDataAdapter
Dim Sqlconn As New SqlConnection
Dim dt As New DataTable
Sql = "Sql Statement here;"
Sqlconn.ConnectionString = connection
Try
Command.Connection = Sqlconn
Command.CommandText = Sql
Adapter.SelectCommand = Command
Adapter.Fill(dt)
If dt.Rows.Count() > 0 Then
DataGridView1 = dt
Else
DataGridView1 = Nothing
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
Using DataSet
Dim Sql As String
Dim Command As New SqlCommand... See More
Dim Adapter As New SqlDataAdapter
Dim Sqlconn As New SqlConnection
Dim ds As New DataSet
Sql = "Sql Statement here;"
Sqlconn.ConnectionString = connection
Try
Command.Connection = Sqlconn
Command.CommandText = Sql
Adapter.SelectCommand = Command
Adapter.Fill(ds)
If dt.Tables(0).Rows.Count() > 0 Then
DataGridView1 = dt
Else
DataGridView1 = Nothing
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
Using DataTable then its work
Dim Sql As String
Dim Command As New SqlCommand
Dim Adapter As New SqlDataAdapter
Dim Sqlconn As New SqlConnection
Dim dt As New DataTable
Sql = "Sql Statement here;"
Sqlconn.ConnectionString = connection
Try
Command.Connection = Sqlconn
Command.CommandText = Sql
Adapter.SelectCommand = Command
Adapter.Fill(dt)
If dt.Rows.Count() > 0 Then
DataGridView1 = dt
Else
DataGridView1 = Nothing
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try