In a data grid using Access as the data source..
The da.update is failing with
"object reference not set to an instance of anobject"
It looks like everything is ok and I was wondering if there is a problem
that I have a bool column mapping to a yes/no type.
__________________________________
Here is the code:
Private Sub PopulateProductGrid()
Dim conn As New
System.Data.OleDb.OleDbConnection("Provider=Micros oft.Jet.OLEDB.4.0;Data
source='C:\Program Files\MyProgramArea\Pricing\Pricing.mdb';Persist Security
Info=False")
Dim sSQL As String
sSQL = "select * from ProductNames"
conn.Open()
Dim da As New System.Data.OleDb.OleDbDataAdapter(sSQL, conn)
Dim cb As New OleDb.OleDbCommandBuilder(da)
Try
da.Fill(myDS, "ProductNames")
DataGrid1.DataSource = myDS
DataGrid1.DataMember = "ProductNames"
Dim irow As Integer
Dim icol As Integer
irow = 0
DataGrid1.Select(irow)
DataGrid1.SetDataBinding(myDS, "ProductNames")
RowCount = DataGrid1.BindingContext(myDS, "ProductNames").Count()
Catch ex As Exception
MessageBox.Show("Failed to connect to data source")
Finally
'conn.Close()
End Try
End Sub
Private Sub ProductTypeSelection_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load
PopulateProductGrid()
StoreNameOut.Text = StoreName
VolumeDiscountOut.Text = VolumeDiscount
'
' Create a Grid Table Style. Map it to the "Product Names" Table.
'
Dim aGridTableStyle As New DataGridTableStyle
aGridTableStyle.MappingName = "ProductNames"
aGridTableStyle.AlternatingBackColor = Color.Lavender
'
' Create GridColumnStyle objects for the grid columns
'
Dim aCol1 As New DataGridTextBoxColumn
Dim aCol2 As New DataGridTextBoxColumn
Dim aCol3 As New DataGridBoolColumn
'
With aCol1
..HeaderText = "Code"
..MappingName = "CODE_VALUE"
..Width = 50
..Alignment = HorizontalAlignment.Center
..TextBox.Enabled = False
End With
'
' Set column's caption, width and disable editing.
'
With aCol2
..MappingName = "CODE_MEANING"
..HeaderText = "Prodcut Type"
..Width = 515
..Alignment = HorizontalAlignment.Left
..TextBox.Enabled = False
End With
With aCol3
..MappingName = "CODE_Selected"
..HeaderText = "Select"
..Width = 50
..Alignment = HorizontalAlignment.Center
End With
'
' Add the GridColumnStyles to the DataGrid's Column Styles collection.
'
With aGridTableStyle.GridColumnStyles
..Add(aCol1)
..Add(aCol2)
..Add(aCol3)
End With
'
' Add the GridColumnStyles to the aGridTableStyle.
'
DataGrid1.TableStyles.Add(aGridTableStyle)
End Sub
Private Sub DataGrid1_Navigate(ByVal sender As System.Object, ByVal ne As
System.Windows.Forms.NavigateEventArgs) Handles DataGrid1.Navigate
End Sub
Private Sub NextButton_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles NextButton.Click
DataGrid1.DataSource = myDS
DataGrid1.DataMember = "ProductNames"
Try
da.Update(myDS, "ProductNames")
Catch ex As Exception
MsgBox(ex.Message)
End Try
PricingForm.StoreName = StoreName
PricingForm.VolumeDiscount = VolumeDiscount
PricingForm.Show()
End Sub 4 1415
da is only visible in the PopulateProductGrid() sub. If you want to use
it in other places in the class move it outside that sub.
Stephen Plotnick wrote:
In a data grid using Access as the data source..
The da.update is failing with
"object reference not set to an instance of anobject"
It looks like everything is ok and I was wondering if there is a problem
that I have a bool column mapping to a yes/no type.
__________________________________
Here is the code:
Private Sub PopulateProductGrid()
Dim conn As New
System.Data.OleDb.OleDbConnection("Provider=Micros oft.Jet.OLEDB.4.0;Data
source='C:\Program Files\MyProgramArea\Pricing\Pricing.mdb';Persist Security
Info=False")
Dim sSQL As String
sSQL = "select * from ProductNames"
conn.Open()
Dim da As New System.Data.OleDb.OleDbDataAdapter(sSQL, conn)
Dim cb As New OleDb.OleDbCommandBuilder(da)
Try
da.Fill(myDS, "ProductNames")
DataGrid1.DataSource = myDS
DataGrid1.DataMember = "ProductNames"
Dim irow As Integer
Dim icol As Integer
irow = 0
DataGrid1.Select(irow)
DataGrid1.SetDataBinding(myDS, "ProductNames")
RowCount = DataGrid1.BindingContext(myDS, "ProductNames").Count()
Catch ex As Exception
MessageBox.Show("Failed to connect to data source")
Finally
'conn.Close()
End Try
End Sub
Private Sub ProductTypeSelection_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load
PopulateProductGrid()
StoreNameOut.Text = StoreName
VolumeDiscountOut.Text = VolumeDiscount
'
' Create a Grid Table Style. Map it to the "Product Names" Table.
'
Dim aGridTableStyle As New DataGridTableStyle
aGridTableStyle.MappingName = "ProductNames"
aGridTableStyle.AlternatingBackColor = Color.Lavender
'
' Create GridColumnStyle objects for the grid columns
'
Dim aCol1 As New DataGridTextBoxColumn
Dim aCol2 As New DataGridTextBoxColumn
Dim aCol3 As New DataGridBoolColumn
'
With aCol1
.HeaderText = "Code"
.MappingName = "CODE_VALUE"
.Width = 50
.Alignment = HorizontalAlignment.Center
.TextBox.Enabled = False
End With
'
' Set column's caption, width and disable editing.
'
With aCol2
.MappingName = "CODE_MEANING"
.HeaderText = "Prodcut Type"
.Width = 515
.Alignment = HorizontalAlignment.Left
.TextBox.Enabled = False
End With
With aCol3
.MappingName = "CODE_Selected"
.HeaderText = "Select"
.Width = 50
.Alignment = HorizontalAlignment.Center
End With
'
' Add the GridColumnStyles to the DataGrid's Column Styles collection.
'
With aGridTableStyle.GridColumnStyles
.Add(aCol1)
.Add(aCol2)
.Add(aCol3)
End With
'
' Add the GridColumnStyles to the aGridTableStyle.
'
DataGrid1.TableStyles.Add(aGridTableStyle)
End Sub
Private Sub DataGrid1_Navigate(ByVal sender As System.Object, ByVal ne As
System.Windows.Forms.NavigateEventArgs) Handles DataGrid1.Navigate
End Sub
Private Sub NextButton_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles NextButton.Click
DataGrid1.DataSource = myDS
DataGrid1.DataMember = "ProductNames"
Try
da.Update(myDS, "ProductNames")
Catch ex As Exception
MsgBox(ex.Message)
End Try
PricingForm.StoreName = StoreName
PricingForm.VolumeDiscount = VolumeDiscount
PricingForm.Show()
End Sub
I think I'm doing this correctly. This was already in my code.
Public Class ProductTypeSelection
Inherits System.Windows.Forms.Form
Private myDS As New DataSet
Dim PricingForm As New PricingForm
Dim RowCount As Integer
Public Shared StoreName As String
Public Shared VolumeDiscount As String
Private da As System.Data.OleDb.OleDbDataAdapter
Private cb As System.Data.OleDb.OleDbCommandBuilder
Thanks for you assistance,
Steve
"Izzy" <is************@gmail.comwrote in message
news:11**********************@c28g2000cwb.googlegr oups.com...
da is only visible in the PopulateProductGrid() sub. If you want to use
it in other places in the class move it outside that sub.
Stephen Plotnick wrote:
>In a data grid using Access as the data source..
The da.update is failing with "object reference not set to an instance of anobject"
It looks like everything is ok and I was wondering if there is a problem that I have a bool column mapping to a yes/no type.
__________________________________ Here is the code:
Private Sub PopulateProductGrid()
Dim conn As New System.Data.OleDb.OleDbConnection("Provider=Micro soft.Jet.OLEDB.4.0;Data source='C:\Program Files\MyProgramArea\Pricing\Pricing.mdb';Persist Security Info=False")
Dim sSQL As String
sSQL = "select * from ProductNames"
conn.Open()
Dim da As New System.Data.OleDb.OleDbDataAdapter(sSQL, conn)
Dim cb As New OleDb.OleDbCommandBuilder(da)
Try
da.Fill(myDS, "ProductNames")
DataGrid1.DataSource = myDS
DataGrid1.DataMember = "ProductNames"
Dim irow As Integer
Dim icol As Integer
irow = 0
DataGrid1.Select(irow)
DataGrid1.SetDataBinding(myDS, "ProductNames")
RowCount = DataGrid1.BindingContext(myDS, "ProductNames").Count()
Catch ex As Exception
MessageBox.Show("Failed to connect to data source")
Finally
'conn.Close()
End Try
End Sub
Private Sub ProductTypeSelection_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PopulateProductGrid()
StoreNameOut.Text = StoreName
VolumeDiscountOut.Text = VolumeDiscount
'
' Create a Grid Table Style. Map it to the "Product Names" Table.
'
Dim aGridTableStyle As New DataGridTableStyle
aGridTableStyle.MappingName = "ProductNames"
aGridTableStyle.AlternatingBackColor = Color.Lavender
'
' Create GridColumnStyle objects for the grid columns
'
Dim aCol1 As New DataGridTextBoxColumn
Dim aCol2 As New DataGridTextBoxColumn
Dim aCol3 As New DataGridBoolColumn
'
With aCol1
.HeaderText = "Code"
.MappingName = "CODE_VALUE"
.Width = 50
.Alignment = HorizontalAlignment.Center
.TextBox.Enabled = False
End With
'
' Set column's caption, width and disable editing.
'
With aCol2
.MappingName = "CODE_MEANING"
.HeaderText = "Prodcut Type"
.Width = 515
.Alignment = HorizontalAlignment.Left
.TextBox.Enabled = False
End With
With aCol3
.MappingName = "CODE_Selected"
.HeaderText = "Select"
.Width = 50
.Alignment = HorizontalAlignment.Center
End With '
' Add the GridColumnStyles to the DataGrid's Column Styles collection.
'
With aGridTableStyle.GridColumnStyles
.Add(aCol1)
.Add(aCol2)
.Add(aCol3)
End With
'
' Add the GridColumnStyles to the aGridTableStyle.
'
DataGrid1.TableStyles.Add(aGridTableStyle)
End Sub
Private Sub DataGrid1_Navigate(ByVal sender As System.Object, ByVal ne As System.Windows.Forms.NavigateEventArgs) Handles DataGrid1.Navigate
End Sub
Private Sub NextButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NextButton.Click
DataGrid1.DataSource = myDS
DataGrid1.DataMember = "ProductNames"
Try
da.Update(myDS, "ProductNames")
Catch ex As Exception
MsgBox(ex.Message)
End Try
PricingForm.StoreName = StoreName
PricingForm.VolumeDiscount = VolumeDiscount
PricingForm.Show()
End Sub
I fixed this:
Dim da As New System.Data.OleDb.OleDbDataAdapter
Dim cb As System.Data.OleDb.OleDbCommandBuilder
WHen there is not a row change it does go through, when a row changes I get
this message:
Update requires a valid UpdateCommand when passed DataRow collection with
modified rows
Thanks,
Steve
"Izzy" <is************@gmail.comwrote in message
news:11**********************@c28g2000cwb.googlegr oups.com...
da is only visible in the PopulateProductGrid() sub. If you want to use
it in other places in the class move it outside that sub.
Stephen Plotnick wrote:
>In a data grid using Access as the data source..
The da.update is failing with "object reference not set to an instance of anobject"
It looks like everything is ok and I was wondering if there is a problem that I have a bool column mapping to a yes/no type.
__________________________________ Here is the code:
Private Sub PopulateProductGrid()
Dim conn As New System.Data.OleDb.OleDbConnection("Provider=Micro soft.Jet.OLEDB.4.0;Data source='C:\Program Files\MyProgramArea\Pricing\Pricing.mdb';Persist Security Info=False")
Dim sSQL As String
sSQL = "select * from ProductNames"
conn.Open()
Dim da As New System.Data.OleDb.OleDbDataAdapter(sSQL, conn)
Dim cb As New OleDb.OleDbCommandBuilder(da)
Try
da.Fill(myDS, "ProductNames")
DataGrid1.DataSource = myDS
DataGrid1.DataMember = "ProductNames"
Dim irow As Integer
Dim icol As Integer
irow = 0
DataGrid1.Select(irow)
DataGrid1.SetDataBinding(myDS, "ProductNames")
RowCount = DataGrid1.BindingContext(myDS, "ProductNames").Count()
Catch ex As Exception
MessageBox.Show("Failed to connect to data source")
Finally
'conn.Close()
End Try
End Sub
Private Sub ProductTypeSelection_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PopulateProductGrid()
StoreNameOut.Text = StoreName
VolumeDiscountOut.Text = VolumeDiscount
'
' Create a Grid Table Style. Map it to the "Product Names" Table.
'
Dim aGridTableStyle As New DataGridTableStyle
aGridTableStyle.MappingName = "ProductNames"
aGridTableStyle.AlternatingBackColor = Color.Lavender
'
' Create GridColumnStyle objects for the grid columns
'
Dim aCol1 As New DataGridTextBoxColumn
Dim aCol2 As New DataGridTextBoxColumn
Dim aCol3 As New DataGridBoolColumn
'
With aCol1
.HeaderText = "Code"
.MappingName = "CODE_VALUE"
.Width = 50
.Alignment = HorizontalAlignment.Center
.TextBox.Enabled = False
End With
'
' Set column's caption, width and disable editing.
'
With aCol2
.MappingName = "CODE_MEANING"
.HeaderText = "Prodcut Type"
.Width = 515
.Alignment = HorizontalAlignment.Left
.TextBox.Enabled = False
End With
With aCol3
.MappingName = "CODE_Selected"
.HeaderText = "Select"
.Width = 50
.Alignment = HorizontalAlignment.Center
End With '
' Add the GridColumnStyles to the DataGrid's Column Styles collection.
'
With aGridTableStyle.GridColumnStyles
.Add(aCol1)
.Add(aCol2)
.Add(aCol3)
End With
'
' Add the GridColumnStyles to the aGridTableStyle.
'
DataGrid1.TableStyles.Add(aGridTableStyle)
End Sub
Private Sub DataGrid1_Navigate(ByVal sender As System.Object, ByVal ne As System.Windows.Forms.NavigateEventArgs) Handles DataGrid1.Navigate
End Sub
Private Sub NextButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NextButton.Click
DataGrid1.DataSource = myDS
DataGrid1.DataMember = "ProductNames"
Try
da.Update(myDS, "ProductNames")
Catch ex As Exception
MsgBox(ex.Message)
End Try
PricingForm.StoreName = StoreName
PricingForm.VolumeDiscount = VolumeDiscount
PricingForm.Show()
End Sub
I've resolved my problems.
I'm posting here in case anybody has the same problem.
Steve
If myDS.HasChanges Then
Dim conn As New
System.Data.OleDb.OleDbConnection("Provider=Micros oft.Jet.OLEDB.4.0;Data
source='C:\Program Files\MyArea\Pricing\Pricing.mdb';Persist Security
Info=False")
Dim uSql = "Select * from ProductNames"
da.SelectCommand = New OleDb.OleDbCommand(uSql, conn)
Dim cb As New OleDb.OleDbCommandBuilder(da)
Try
myDS.Tables("ProductNames").GetChanges()
da.Update(myDS.Tables("ProductNames"))
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End If
"Stephen Plotnick" <sp*******@groupcbf.comwrote in message
news:P6******************************@giganews.com ...
>I fixed this:
Dim da As New System.Data.OleDb.OleDbDataAdapter
Dim cb As System.Data.OleDb.OleDbCommandBuilder
WHen there is not a row change it does go through, when a row changes I
get this message:
Update requires a valid UpdateCommand when passed DataRow collection with
modified rows
Thanks,
Steve
"Izzy" <is************@gmail.comwrote in message
news:11**********************@c28g2000cwb.googlegr oups.com...
>da is only visible in the PopulateProductGrid() sub. If you want to use it in other places in the class move it outside that sub.
Stephen Plotnick wrote:
>>In a data grid using Access as the data source..
The da.update is failing with "object reference not set to an instance of anobject"
It looks like everything is ok and I was wondering if there is a problem that I have a bool column mapping to a yes/no type.
__________________________________ Here is the code:
Private Sub PopulateProductGrid()
Dim conn As New System.Data.OleDb.OleDbConnection("Provider=Micr osoft.Jet.OLEDB.4.0;Data source='C:\Program Files\MyProgramArea\Pricing\Pricing.mdb';Persist Security Info=False")
Dim sSQL As String
sSQL = "select * from ProductNames"
conn.Open()
Dim da As New System.Data.OleDb.OleDbDataAdapter(sSQL, conn)
Dim cb As New OleDb.OleDbCommandBuilder(da)
Try
da.Fill(myDS, "ProductNames")
DataGrid1.DataSource = myDS
DataGrid1.DataMember = "ProductNames"
Dim irow As Integer
Dim icol As Integer
irow = 0
DataGrid1.Select(irow)
DataGrid1.SetDataBinding(myDS, "ProductNames")
RowCount = DataGrid1.BindingContext(myDS, "ProductNames").Count()
Catch ex As Exception
MessageBox.Show("Failed to connect to data source")
Finally
'conn.Close()
End Try
End Sub
Private Sub ProductTypeSelection_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PopulateProductGrid()
StoreNameOut.Text = StoreName
VolumeDiscountOut.Text = VolumeDiscount
'
' Create a Grid Table Style. Map it to the "Product Names" Table.
'
Dim aGridTableStyle As New DataGridTableStyle
aGridTableStyle.MappingName = "ProductNames"
aGridTableStyle.AlternatingBackColor = Color.Lavender
'
' Create GridColumnStyle objects for the grid columns
'
Dim aCol1 As New DataGridTextBoxColumn
Dim aCol2 As New DataGridTextBoxColumn
Dim aCol3 As New DataGridBoolColumn
'
With aCol1
.HeaderText = "Code"
.MappingName = "CODE_VALUE"
.Width = 50
.Alignment = HorizontalAlignment.Center
.TextBox.Enabled = False
End With
'
' Set column's caption, width and disable editing.
'
With aCol2
.MappingName = "CODE_MEANING"
.HeaderText = "Prodcut Type"
.Width = 515
.Alignment = HorizontalAlignment.Left
.TextBox.Enabled = False
End With
With aCol3
.MappingName = "CODE_Selected"
.HeaderText = "Select"
.Width = 50
.Alignment = HorizontalAlignment.Center
End With '
' Add the GridColumnStyles to the DataGrid's Column Styles collection.
'
With aGridTableStyle.GridColumnStyles
.Add(aCol1)
.Add(aCol2)
.Add(aCol3)
End With
'
' Add the GridColumnStyles to the aGridTableStyle.
'
DataGrid1.TableStyles.Add(aGridTableStyle)
End Sub
Private Sub DataGrid1_Navigate(ByVal sender As System.Object, ByVal ne As System.Windows.Forms.NavigateEventArgs) Handles DataGrid1.Navigate
End Sub
Private Sub NextButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NextButton.Click
DataGrid1.DataSource = myDS
DataGrid1.DataMember = "ProductNames"
Try
da.Update(myDS, "ProductNames")
Catch ex As Exception
MsgBox(ex.Message)
End Try
PricingForm.StoreName = StoreName
PricingForm.VolumeDiscount = VolumeDiscount
PricingForm.Show()
End Sub
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Dave |
last post by:
I have 2 tables, one with names, and another with addresses, joined by their
CIVICID number (unique to the ADDRESSINFO table) in Oracle.
I need to update a field in the NAMEINFO table for a...
|
by: Lauren Quantrell |
last post by:
In VBA, I constructed the following to update all records in
tblmyTable with each records in tblmyTableTEMP having the same
UniqueID:
UPDATE
tblMyTable RIGHT JOIN tblMyTableTEMP ON...
|
by: kalamos |
last post by:
This statement fails
update ded_temp a
set a.balance = (select sum(b.ln_amt)
from ded_temp b
where a.cust_no = b.cust_no
and a.ded_type_cd = b.ded_type_cd
and a.chk_no = b.chk_no
group by...
|
by: VK |
last post by:
<http://www.jibbering.com/faq/#FAQ3_2>
The parts where update, replacement
or add-on is needed are in <update> tag.
3.2 What online resources are available?
Javascript FAQ sites, please...
|
by: Philip Boonzaaier |
last post by:
I want to be able to generate SQL statements that will go through a list of
data, effectively row by row, enquire on the database if this exists in the
selected table- If it exists, then the colums...
|
by: Shapper |
last post by:
Hello,
I have created 3 functions to insert, update and delete an Access
database record. The Insert and the Delete code are working fine.
The update is not. I checked and my database has all...
|
by: jaYPee |
last post by:
I have search a lot of thread in google newsgroup and read a lot of
articles but still i don't know how to update the dataset that has 3
tables.
my 3 tables looks like the 3 tables from...
|
by: Zorpiedoman |
last post by:
I keep getting a concurrency exception the second time I make a change and
attempt to update a dataadapter. It appears this is by design, so there must
be something I can do to avoid it.
...
|
by: Stephen Plotnick |
last post by:
I'm very new to VB.NET 2003
Here is what I have accomplished:
MainSelectForm - Selects an item
In a public class I pass a DataViewRow to
ItemInformation1 Form
ItemInformation2 Form
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |