Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Record not display datagridview
but no error in code
when form will be open grid is empty no record
my code as under check this

What I have tried:

Public Class Form6
 
    Dim da As Object
 
    Public Property ServerName() As String
    Public Property DatabaseName() As String
    Public Property Login() As String
    Public Property Password() As String
 
    Private Function SqlConn(Optional ByVal timeout As Integer = 0) As String
                Dim sqlBuilder As New SqlClient.SqlConnectionStringBuilder()
 
                sqlBuilder.DataSource = "Softlinks-PC"
        sqlBuilder.InitialCatalog = "RMS"
        sqlBuilder.IntegratedSecurity = False
        sqlBuilder.MultipleActiveResultSets = True 'to avoid exception if a query uses anothe rquery internal

        sqlBuilder.UserID = "Softlinks-PC\Softlinks"
        sqlBuilder.Password = ""
        If timeout > 0 Then
            sqlBuilder.ConnectTimeout = timeout
        End If
 
        Return sqlBuilder.ToString
    End Function
 
  
    Private Sub Form6_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Call SqlConn()
        Dim sql As String
        Dim ds = New DataSet
        Dim tables = ds.Tables
 
        Sql = "SELECT * FROM Productitem"
        da.Fill(ds, "Productcode")        
        Dim view As New DataView(ds.tables(0))
        DataGridView1.DataSource = view
    End Sub
 
End Class
Posted
Updated 14-Sep-16 18:21pm
v2

1 solution

As I already wrote earlier, you're missing key parts from your code:
- you don't open connection to the database
- you don't set the SQL statement anywhere
- you don't use the connection string anywhere and so on...

So please take some time and go through some examples how to populate a dataset. Here's one to start with: https://support.microsoft.com/en-us/kb/301216[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900