dionysus
New member
- Joined
- Aug 14, 2009
- Messages
- 2
- Programming Experience
- 1-3
Title pretty much says it. I'm trying to run a simple database and im getting a "System.NullReferenceException" error ) & "Additional Information:Object reference not set to an instance of a object" .
txtItemName.Text = rowCurrent.Item("ItemName") <-- highlighted in yellow
Code is as follows:
Thanks for all the help
Cheers, demiurge.
[Note: VB 2003]
txtItemName.Text = rowCurrent.Item("ItemName") <-- highlighted in yellow
Code is as follows:
VB.NET:
Imports System.Data.OleDB
----------------------------------------------------
Public Class Form1
Inherits System.Windows.Forms.Form
----------------------------------------------------
Dim conStock As OleDbConnection
Dim adpStock As OleDbDataAdapter
Dim datStock As New DataSet
Dim rowCurrent As DataRow
Dim ItemID
-----------------------------------------------------
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Key(0) As DataColumn
Dim ConnectString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" + _
"Data Source=database2.mdb"
conStock = New OleDbConnection(ConnectString)
conStock.Open()
adpStock = New OleDbDataAdapter
adpStock.SelectCommand = New OleDbCommand
With adpStock.SelectCommand
.Connection = conStock
.CommandText = "SELECT * FROM tblStock"
.CommandType = CommandType.Text
.ExecuteNonQuery()
End With
adpStock.Fill(datStock, "tblStock")
Key(0) = datStock.Tables("tblStock").Columns(0)
datStock.Tables("tblStock").PrimaryKey = Key
txtItemName.Text = rowCurrent.Item("ItemName")
txtItemID.Text = rowCurrent.Item("ItemID")
txtItemSize.Text = rowCurrent.Item("ItemSize")
txtItemCost.Text = rowCurrent.Item("ItemCost")
txtItemSupplier.Text = rowCurrent.Item("ItemSupplier")
txtItemStock.Text = rowCurrent.Item("AmountInStock")
txtItemType.Text = rowCurrent.Item("ItemType")
txtItemQuantity.Text = rowCurrent.Item("ItemQuantity")
End Sub
Cheers, demiurge.
[Note: VB 2003]
Last edited: