Home
Forums
New posts
Search forums
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
C# Community
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Home
Forums
Database
Database General Discussion
Windows App datarow error
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="cpopham" data-source="post: 107" data-attributes="member: 42"><p>am writing an application where my user makes a selection with a combo box and then it pulls up the appropriate information for the selection. If the user approves of the selection he clicks a button which adds the information to another dataset.</p><p></p><p>Everything works fine except when the button is clicked to add the information to the dataset. </p><p></p><p>I get the error Object reference not set to an instance of an object.</p><p></p><p>Here should be the appropriate <a href="http://experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21016507.html#">code</a>:</p><p></p><p>This is the button to add the information to the dataset. The DataTier is a separate class for all of my data manipulation.</p><p></p><p> Private Sub btnAddPO_Click(ByVal sender As Object, _</p><p>ByVal e As System.EventArgs) _</p><p>Handles btnAddPO.Click</p><p> Dim ds As DataSet</p><p> Dim strDate As Date = Today</p><p> Dim strPO As String = mstrSelectedPO</p><p> Dim strSpend As String = Me.lblSpend.Text</p><p> Dim strVend As String = Me.lblVendor.Text</p><p> Dim strBuy As String = Me.lblBuyer.Text</p><p></p><p> mobjDataTier = New DataTier</p><p> ds = mobjDataTier.AddAGPO(strDate, strPO, strSpend, strVend, strBuy)</p><p></p><p> Me.dgAGPOs.DataSource = ds</p><p> Me.dgAGPOs.DataMember = "AGPOInfo"</p><p> Me.dgAGPOs.Refresh()</p><p> End Sub</p><p></p><p>This is the code in my data class which is giving me the error:</p><p></p><p></p><p> Public Function AddAGPO(ByVal strDate As String, _</p><p> ByVal strPONum As String, _</p><p> ByVal strSpend As String, _</p><p> ByVal strVend As String, _</p><p> ByVal strBuyer As String) _</p><p> As DataSet</p><p> Try</p><p> If blnCreated = False Then</p><p> dsAGPOs = New DataSet</p><p> With dsAGPOs.Tables.Add("AGPO")</p><p> .Columns.Add("ToAG", GetType(String))</p><p> .Columns.Add("PONum", GetType(String))</p><p> .Columns.Add("Vendor", GetType(String))</p><p> .Columns.Add("Buyer", GetType(String))</p><p> End With</p><p></p><p> blnCreated = True</p><p> End If</p><p></p><p> Dim myRow As DataRow</p><p></p><p> myRow = dsAGPOs.Tables("AGPOInfo").NewRow ‘This is the row that is causing the error.</p><p></p><p> myRow.Item(0) = strDate</p><p> myRow.Item(1) = strPONum</p><p> myRow.Item(2) = strSpend</p><p> myRow.Item(3) = strVend</p><p> myRow.Item(4) = strBuyer</p><p></p><p> dsAGPOs.Tables("AGPOInfo").Rows.Add(myRow)</p><p></p><p> Return dsAGPOs</p><p></p><p></p><p> Catch ex As Exception</p><p> MessageBox.Show(ex.Message)</p><p></p><p> End Try</p><p></p><p> End Function</p><p></p><p>Any Ideas?</p><p>Chester</p></blockquote><p></p>
[QUOTE="cpopham, post: 107, member: 42"] am writing an application where my user makes a selection with a combo box and then it pulls up the appropriate information for the selection. If the user approves of the selection he clicks a button which adds the information to another dataset. Everything works fine except when the button is clicked to add the information to the dataset. I get the error Object reference not set to an instance of an object. Here should be the appropriate [url="http://experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21016507.html#"]code[/url]: This is the button to add the information to the dataset. The DataTier is a separate class for all of my data manipulation. Private Sub btnAddPO_Click(ByVal sender As Object, _ ByVal e As System.EventArgs) _ Handles btnAddPO.Click Dim ds As DataSet Dim strDate As Date = Today Dim strPO As String = mstrSelectedPO Dim strSpend As String = Me.lblSpend.Text Dim strVend As String = Me.lblVendor.Text Dim strBuy As String = Me.lblBuyer.Text mobjDataTier = New DataTier ds = mobjDataTier.AddAGPO(strDate, strPO, strSpend, strVend, strBuy) Me.dgAGPOs.DataSource = ds Me.dgAGPOs.DataMember = "AGPOInfo" Me.dgAGPOs.Refresh() End Sub This is the code in my data class which is giving me the error: Public Function AddAGPO(ByVal strDate As String, _ ByVal strPONum As String, _ ByVal strSpend As String, _ ByVal strVend As String, _ ByVal strBuyer As String) _ As DataSet Try If blnCreated = False Then dsAGPOs = New DataSet With dsAGPOs.Tables.Add("AGPO") .Columns.Add("ToAG", GetType(String)) .Columns.Add("PONum", GetType(String)) .Columns.Add("Vendor", GetType(String)) .Columns.Add("Buyer", GetType(String)) End With blnCreated = True End If Dim myRow As DataRow myRow = dsAGPOs.Tables("AGPOInfo").NewRow ‘This is the row that is causing the error. myRow.Item(0) = strDate myRow.Item(1) = strPONum myRow.Item(2) = strSpend myRow.Item(3) = strVend myRow.Item(4) = strBuyer dsAGPOs.Tables("AGPOInfo").Rows.Add(myRow) Return dsAGPOs Catch ex As Exception MessageBox.Show(ex.Message) End Try End Function Any Ideas? Chester [/QUOTE]
Insert quotes…
Verification
Post reply
Home
Forums
Database
Database General Discussion
Windows App datarow error
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.
Accept
Learn more…
Top
Bottom