prav_roy
Well-known member
hi,
my problem is, i have a class and in that class i have a method to fill datagrid, in one of my form i am creating an object of that class and i m calling the method by passing variables my code looks something like
// My class starts here
Public Class DataControl
Public Sub Gridfill(ByRef grid As DataGrid, ByVal str As String)
Dim cmd As New SqlCommand()
Dim ds As New DataSet()
Dim da As New SqlDataAdapter()
cmd.CommandText = str
cmd.Connection = dbconn
da.SelectCommand = cmd
Dim dt As New DataTable()
da.Fill(ds)
dt = ds.Tables(0)
Dim dv As DataView = New DataView(dt)
grid.DataSource = dv
End Sub
End class
//class ends here
//im calling gridfill method of above class here
Dim datadb As DataControl //object of the class
Private Sub frmSearch_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim stng As String = "select * from viewer_response"
datadb.Gridfill(DataGrid1, stng) //call method
//i get error in above line System.NullReferenceException
End Sub
plz tel me where do i going wrong
my problem is, i have a class and in that class i have a method to fill datagrid, in one of my form i am creating an object of that class and i m calling the method by passing variables my code looks something like
// My class starts here
Public Class DataControl
Public Sub Gridfill(ByRef grid As DataGrid, ByVal str As String)
Dim cmd As New SqlCommand()
Dim ds As New DataSet()
Dim da As New SqlDataAdapter()
cmd.CommandText = str
cmd.Connection = dbconn
da.SelectCommand = cmd
Dim dt As New DataTable()
da.Fill(ds)
dt = ds.Tables(0)
Dim dv As DataView = New DataView(dt)
grid.DataSource = dv
End Sub
End class
//class ends here
//im calling gridfill method of above class here
Dim datadb As DataControl //object of the class
Private Sub frmSearch_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim stng As String = "select * from viewer_response"
datadb.Gridfill(DataGrid1, stng) //call method
//i get error in above line System.NullReferenceException
End Sub
plz tel me where do i going wrong