Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to display record in Datagridview1 with sql server but record does not display
in Datagridview1 and there is no error in code.
I hope you will solve this problem.

Regards

Mahmood

What I have tried:

VB.NET
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
        ' Initialize the connection string builder for the 
        ' underlying provider. 
        Dim sqlBuilder As New SqlClient.SqlConnectionStringBuilder()

        ' Set the properties for the data source. 
        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") 'Change items to your database name 
        Dim view As New DataView(tables(0))
        DataGridView1.DataSource = view
    End Sub

End Class
Posted
Updated 14-Sep-16 4:37am
v2
Comments
[no name] 14-Sep-16 10:03am    
Time for you to learn how to use the debugger.
RickZeeland 14-Sep-16 10:22am    
Yes, use the debugger, see here on how to use it: https://msdn.microsoft.com/en-us/library/x85tt0dd.aspx

1 solution

You are defining "da" as an object and never giving it a value so I don't know how this compiles and doesn't error when it runs.

Remove your declaration of da at the top and do it in your Load event.

VB.NET
Dim da = New SqlDataAdapter


Also remove the "tables" variable and do this instead

VB.NET
Dim view As New DataView(ds.Tables(0))
 
Share this answer
 
Comments
Karthik_Mahalingam 14-Sep-16 13:09pm    
5

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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