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;" & _

    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")
            Dim command As New SqlCommand(SelectQry, connection)
            Dim adapter = New SqlDataAdapter(command)
        Catch ex As Exception
            returnData = Nothing
            If connection.State = ConnectionState.Open Then
            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

Edited 6 Years Ago by Kingcoder210: n/a

1: You did not bind the datagridview

dg1.DataSource = GetData()

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

This article has been dead for over six months. Start a new discussion instead.