Click here to Skip to main content
15,900,907 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have written following codes to show records in a datagridview. But it doesnt work & it shows nothing!
Would you please check my code & tell me where did I make mistake? Please add example with your answer because I am just a beginner.

VB
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
Posted
Updated 12-Sep-10 10:36am
v2

Add this too to your code
dg1.DataBind()


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


or use
XML
Private Sub cmbdmidt_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbdmidt.Leave
     dg1.DataSource = Nothing
     dg1.DataSource = GetData()
     dg1.DataMember="tablename"
 End Sub


Hoping this will help you   :)
 
Share this answer
 
v4
VB
dg1.DataSource = Nothing
  dg1.DataSource = GetData()
  dg1.dataBind()
 
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