I am trying to show info at the bottom of my data grid I get error saying object reference not set to an instance of an object Here is my code Imports System.data
Imports System.data.OleDb
Imports System.Configuration
Partial Class supplier
Inherits System.Web.UI.Page
Dim ConnString As String = ConfigurationManager.AppSettings("ConnString")
Dim dbPath As String = ConfigurationManager.AppSettings("PathDB")
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
getsuppliers()
dgsuppliers.DataSource = Session("Suppliers")
End If
End Sub
Private Sub getsuppliers()
Dim mySQL As String = "select * from Suppliers "
Dim dbConn As New OleDbConnection(ConnString & Server.MapPath(dbPath))
Dim dbCommand As New OleDbCommand(mySQL, dbConn)
Dim dbAdapter As New OleDbDataAdapter(dbCommand)
Dim dsSuppliers As New DataSet
Try
dbConn.Open()
dbAdapter.Fill(dsSuppliers, "Suppliers")
Catch ex As Exception
lblResults.Text = "Error occurred when retrieving data from Table: " & ex.Message
Finally
dbConn.Close()
End Try
dgsuppliers.DataSource = dsSuppliers
dgsuppliers.DataBind()
End Sub
Private Sub dgsuppliers_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles dgsuppliers.PageIndexChanging
End Sub
Protected Sub dgsuppliers_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgsuppliers.SelectedIndexChanged
Dim mysql As String = "Select * from Suppliers where SupplierID=" & dgsuppliers.SelectedValue & ""
Dim dbConn As New OleDbConnection(ConnString & Server.MapPath(dbPath))
Dim dbCommand As New OleDbCommand(mysql, dbConn)
Dim dbAdapter As New OleDbDataAdapter(dbCommand)
Dim dsSuppliers As New DataSet
Dim supplierRow As DataRow
supplierRow = dsSuppliers.Tables("Suppliers").Rows(0)
supplierRow("CompanyName") = lblName.Text
supplierRow("ContactName") = lblContact.Text
supplierRow("ContactTitle") = lblTitle.Text
supplierRow("Address") = lblAddress.Text
supplierRow("City") = lblCity.Text
supplierRow("Region") = lblRegion.Text
supplierRow("PostalCode") = lblPostal.Text
supplierRow("Country") = lblCountry.Text
supplierRow("Phone") = lblPhone.Text
supplierRow("Fax") = lblFax.Text
supplierRow("Homepage") = lblHomepage.Text
dsSuppliers.Tables.Add("Suppliers").Rows.Add(supplierRow)
dgsuppliers.DataSource = dsSuppliers.Tables
End Sub
End Class