I have used following code to show records there in a datagridview but it doesnt work. Even it shows nothing. Please check it & tell me what did I make mistake. Please add example with your answer because I am just a beginner.

Imports System.Data.SqlClient

Public Class Form34
    Private Const ConnectionString As String = "Server=.\SQLEXPRESS;" & _
    "Database=SUIMT;Trusted_Connection=True"

    Public Function GetData() As DataTable
        Dim SelectQry = "Select row_num, stu_id, tot_amou, paid, du, aoins, due, dt From monthly_instal where stu_id = '" & cmbdmiidn.Text & "' AND dt = '" & cmbdmidt.Text & "'"
        Dim connection As New SqlConnection(ConnectionString)
        Dim returnData As New DataTable("monthly_instal")
        Try
            connection.Open()
            Dim command As New SqlCommand(SelectQry, connection)
            Dim adapter = New SqlDataAdapter(command)
            adapter.Fill(returnData)
            con.Close()
        Catch ex As Exception
            returnData = Nothing
            If connection.State = ConnectionState.Open Then
                connection.Close()
            End If
        End Try
        Return returnData
    End Function

    Private Sub cmbdmidt_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbdmidt.Leave
     dg1.DataSource = Nothing
     dg1.DataSource = GetData()
 End Sub

1: You did not bind the datagridview

dg1.DataSource = GetData()
dg1.DataBind()

2: Check if you got any exceptions thrown or not.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.