not too sure why this problem is happening. I can update the dataset from a textbox but then when I click the update button it is showing an error "Object reference not set to an instance of an object." The dataset is empty when I try to run the update. Hope someone can helpme out on this one. code is:-

Private Sub btnSubReturn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubReturn.Click
        Dim Qtyint As Integer
        Dim QtyRetInt As Integer
        Dim Result As Integer
        Dim i As Integer

        
        Qtyint = Integer.Parse(Me.txtQty.Text)
        QtyRetInt = Integer.Parse(Me.txtQtyReturn.Text)



        txtResult.Text = Qtyint + QtyRetInt
        Result = txtResult.Text


        i = dgLinenStock.CurrentRow.Index
        dgLinenStock.Item(4, i).Value = Result

        


    End Sub

    
    
    Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
        Dim Builder As New SqlCommandBuilder(daLinStock)

        daLinStock.Update(ds)


    End Sub

Its hard to say since you're referencing variables declared outside the scope of your project but obviously something is null. Which line of code is raising the exception?

Hi Sknake,
the line of code that is throwing the exception is "daLinStock.Update(ds)
When It tries to do the update I thing the dataset is empty but I don't know why.
Thanks

Hi Sknake,
the line of code that is throwing the exception is "daLinStock.Update(ds)
When It tries to do the update I thing the dataset is empty but I don't know why.
Thanks

Where and how did you declare the variable "ds" ?

Hi Sknake,
the line of code that is throwing the exception is "daLinStock.Update(ds)
When It tries to do the update I thing the dataset is empty but I don't know why.
Thanks

Does it make any difference that I am using a sql View to populate the dataset which is read only on the sql server??? Just a thought

Dim daLinStock As New SqlDataAdapter("Select PackIndex,DateOut Account,LinenItem,Qty,QtyRet,ReturnDate from dbo.VwLinenStock Where Account like '" & Me.txtAcc.Text & "'", Con)




        daLinStock.Fill(ds, "LinenStock")
        


        Dim dc As DataColumn

        dc = New DataColumn("Outstanding", Type.GetType("System.Double"))

        dc.Expression = "Qty - QtyRet"
        ds.Tables("LinenStock").Columns.Add(dc)
        dgLinenStock.DataSource = ds.Tables("LinenStock")
        dgLinenStock.Columns("PackIndex").Visible = False
        dgLinenStock.Columns("Account").Visible = False
        dgLinenStock.Columns("Qty").Visible = False

        dgLinenStock.Columns("LinenItem").Width = 220
        dgLinenStock.Columns("ReturnDate").Width = 110
        dgLinenStock.AllowUserToAddRows = False

the ds is declared at the top of the class

Imports System.Data
Imports System.Data.SqlClient
Public Class CustomerDetail
    
    Dim Con As SqlConnection
    Dim DaLinStock As SqlDataAdapter
    Dim ds As DataSet

    Private Sub CustomerDetail_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Con = New SqlConnection("Data Source=WHITES;Initial Catalog=ESHAN;Integrated Security=True")
        Con.Open()
        Dim ds As New DataSet
        Dim da As New SqlDataAdapter("Select * From dbo.dbo_SLMaster WHERE Name like '" & Main_Screen.cboLinenCust.Text & "'", Con)
        da.Fill(ds, "CustomerDetail")

        txtAcc.Text = ds.Tables("CustomerDetail").Rows(0).Item("AccountNo")
        txtName.Text = ds.Tables("CustomerDetail").Rows(0).Item("Name")
        txtAdd1.Text = ds.Tables("CustomerDetail").Rows(0).Item("Address1")
        txtAdd2.Text = ds.Tables("CustomerDetail").Rows(0).Item("Address2")
        txtAdd3.Text = ds.Tables("CustomerDetail").Rows(0).Item("Address3")
        txtAdd4.Text = ds.Tables("CustomerDetail").Rows(0).Item("Contact")
        txtEmail.Text = ds.Tables("CustomerDetail").Rows(0).Item("Email")
        txtPhone.Text = ds.Tables("CustomerDetail").Rows(0).Item("Phone")
        txtFax.Text = ds.Tables("CustomerDetail").Rows(0).Item("FaxNo")
        txtMobile.Text = ds.Tables("CustomerDetail").Rows(0).Item("MobileNo")
        txtPost.Text = ds.Tables("CustomerDetail").Rows(0).Item("PostCode")
This article has been dead for over six months. Start a new discussion instead.