473,396 Members | 1,898 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

DataAdapter Update

Jon
Hi,

I have a function to fill the data into the dataset:

Private Sub LoadSystemDataDB(ByVal m_str As String, ByVal da As _
OleDbDataAdapter, ByVal tbName As String)
Dim OleDbConn As New OleDbConnection(OLEDB_CONNECTION_1)
OleDbConn.Open()
da = New OleDbDataAdapter(m_str, OleDbConn)
Dim cmd As New OleDbCommandBuilder(da)
da.Fill(dsDataSet, tbName)
dsDataSet.CaseSensitive = True
OleDbConn.Close()
End Sub

However when i try to update the data using:
Dim autogen As New OleDbCommandBuilder(daLoginDetails)
daDataAdapter.Update(dsDataSet, "myTable")

I get error when i try to update it. The error is on the Update line where
it saids "The DataAdapter.SelectCommand property needs to be initialized".

So i guess i was doing something wrong when filling the data??
or what is the proper way to make a fill data function? as i have many
tables to load into the dataset.

Hope anyone can help?
many thanks.
Nov 21 '05 #1
9 8375
Try something like this:

da.SelectCommand = cmd
da.Fill(dsDataSet, tbName)
"Jon" wrote:
Hi,

I have a function to fill the data into the dataset:

Private Sub LoadSystemDataDB(ByVal m_str As String, ByVal da As _
OleDbDataAdapter, ByVal tbName As String)
Dim OleDbConn As New OleDbConnection(OLEDB_CONNECTION_1)
OleDbConn.Open()
da = New OleDbDataAdapter(m_str, OleDbConn)
Dim cmd As New OleDbCommandBuilder(da)
da.Fill(dsDataSet, tbName)
dsDataSet.CaseSensitive = True
OleDbConn.Close()
End Sub

However when i try to update the data using:
Dim autogen As New OleDbCommandBuilder(daLoginDetails)
daDataAdapter.Update(dsDataSet, "myTable")

I get error when i try to update it. The error is on the Update line where
it saids "The DataAdapter.SelectCommand property needs to be initialized".

So i guess i was doing something wrong when filling the data??
or what is the proper way to make a fill data function? as i have many
tables to load into the dataset.

Hope anyone can help?
many thanks.

Nov 21 '05 #2
Try placing a

da.SelectCommand = cmd

just prior to your fill statement.
"Jon" wrote:
Hi,

I have a function to fill the data into the dataset:

Private Sub LoadSystemDataDB(ByVal m_str As String, ByVal da As _
OleDbDataAdapter, ByVal tbName As String)
Dim OleDbConn As New OleDbConnection(OLEDB_CONNECTION_1)
OleDbConn.Open()
da = New OleDbDataAdapter(m_str, OleDbConn)
Dim cmd As New OleDbCommandBuilder(da)
da.Fill(dsDataSet, tbName)
dsDataSet.CaseSensitive = True
OleDbConn.Close()
End Sub

However when i try to update the data using:
Dim autogen As New OleDbCommandBuilder(daLoginDetails)
daDataAdapter.Update(dsDataSet, "myTable")

I get error when i try to update it. The error is on the Update line where
it saids "The DataAdapter.SelectCommand property needs to be initialized".

So i guess i was doing something wrong when filling the data??
or what is the proper way to make a fill data function? as i have many
tables to load into the dataset.

Hope anyone can help?
many thanks.

Nov 21 '05 #3
Jon
typo error:
Instead of
daDataAdapter.Update(dsDataSet, "myTable")

It should be:
daLoginDetails.Update(dsDataSet, "myTable")

can anyone help please?
"Jon" wrote:
Hi,

I have a function to fill the data into the dataset:

Private Sub LoadSystemDataDB(ByVal m_str As String, ByVal da As _
OleDbDataAdapter, ByVal tbName As String)
Dim OleDbConn As New OleDbConnection(OLEDB_CONNECTION_1)
OleDbConn.Open()
da = New OleDbDataAdapter(m_str, OleDbConn)
Dim cmd As New OleDbCommandBuilder(da)
da.Fill(dsDataSet, tbName)
dsDataSet.CaseSensitive = True
OleDbConn.Close()
End Sub

However when i try to update the data using:
Dim autogen As New OleDbCommandBuilder(daLoginDetails)
daDataAdapter.Update(dsDataSet, "myTable")

I get error when i try to update it. The error is on the Update line where
it saids "The DataAdapter.SelectCommand property needs to be initialized".

So i guess i was doing something wrong when filling the data??
or what is the proper way to make a fill data function? as i have many
tables to load into the dataset.

Hope anyone can help?
many thanks.

Nov 21 '05 #4
Jon
I tried to add something like that in the function, but it said

"Value of type System.Data.OleDb.OleDbCommand.' cannot be converted to
'System.Data.OleDb.OleDbCommandBuilder'

?
thanks
"Darrell Wesley" wrote:
Try something like this:

da.SelectCommand = cmd
da.Fill(dsDataSet, tbName)
"Jon" wrote:
Hi,

I have a function to fill the data into the dataset:

Private Sub LoadSystemDataDB(ByVal m_str As String, ByVal da As _
OleDbDataAdapter, ByVal tbName As String)
Dim OleDbConn As New OleDbConnection(OLEDB_CONNECTION_1)
OleDbConn.Open()
da = New OleDbDataAdapter(m_str, OleDbConn)
Dim cmd As New OleDbCommandBuilder(da)
da.Fill(dsDataSet, tbName)
dsDataSet.CaseSensitive = True
OleDbConn.Close()
End Sub

However when i try to update the data using:
Dim autogen As New OleDbCommandBuilder(daLoginDetails)
daDataAdapter.Update(dsDataSet, "myTable")

I get error when i try to update it. The error is on the Update line where
it saids "The DataAdapter.SelectCommand property needs to be initialized".

So i guess i was doing something wrong when filling the data??
or what is the proper way to make a fill data function? as i have many
tables to load into the dataset.

Hope anyone can help?
many thanks.

Nov 21 '05 #5
Jon
thanks Darell, i have added the line

da.SelectCommand = cmd

just before the fill method.
but it saids:

"Value of type System.Data.OleDb.OleDbCommand.' cannot be converted to
'System.Data.OleDb.OleDbCommandBuilder' "

hence could not compile.
Do you know the problem?
or is it the wrong method i m filling my dataset or my function?

many thanks. i hope someone can help me please?
Nov 21 '05 #6
I read your post wrong the first time and thought that cmd was a Command
object.

But : I don't believe that you need to create the commandbuilder twice, once
will do. Make certain that the dataset is available to you when the update
method is called and make certain that the connection back to the underlying
database is open.
"Jon" wrote:
thanks Darell, i have added the line

da.SelectCommand = cmd

just before the fill method.
but it saids:

"Value of type System.Data.OleDb.OleDbCommand.' cannot be converted to
'System.Data.OleDb.OleDbCommandBuilder' "

hence could not compile.
Do you know the problem?
or is it the wrong method i m filling my dataset or my function?

many thanks. i hope someone can help me please?

Nov 21 '05 #7
Private Sub LoadSystemDataDB(ByVal m_str As String, ByRef da As _
OleDbDataAdapter, ByVal tbName As String, ByRef cmd as OleDbCommandBuilder)
Dim OleDbConn As New OleDbConnection(OLEDB_CONNECTION_1)
da = New OleDbDataAdapter
da.SelectCommand = new OleDBCommand(m_str, OleDbConn)
Dim cmd As New OleDbCommandBuilder(da)
OleDbConn.Open
da.Fill(dsDataSet, tbName)
dsDataSet.CaseSensitive = True
OleDbConn.Close()
End Sub

Note the "ByRef" in the sub statement, these are Reference objects not value
objects.

"Jon" wrote:
Hi,

I have a function to fill the data into the dataset:

Private Sub LoadSystemDataDB(ByVal m_str As String, ByVal da As _
OleDbDataAdapter, ByVal tbName As String)
Dim OleDbConn As New OleDbConnection(OLEDB_CONNECTION_1)
OleDbConn.Open()
da = New OleDbDataAdapter(m_str, OleDbConn)
Dim cmd As New OleDbCommandBuilder(da)
da.Fill(dsDataSet, tbName)
dsDataSet.CaseSensitive = True
OleDbConn.Close()
End Sub

However when i try to update the data using:
Dim autogen As New OleDbCommandBuilder(daLoginDetails)
daDataAdapter.Update(dsDataSet, "myTable")

I get error when i try to update it. The error is on the Update line where
it saids "The DataAdapter.SelectCommand property needs to be initialized".

So i guess i was doing something wrong when filling the data??
or what is the proper way to make a fill data function? as i have many
tables to load into the dataset.

Hope anyone can help?
many thanks.

Nov 21 '05 #8
Jon
ic, Thank you very much!

"Darrell Wesley" wrote:
Private Sub LoadSystemDataDB(ByVal m_str As String, ByRef da As _
OleDbDataAdapter, ByVal tbName As String, ByRef cmd as OleDbCommandBuilder)
Dim OleDbConn As New OleDbConnection(OLEDB_CONNECTION_1)
da = New OleDbDataAdapter
da.SelectCommand = new OleDBCommand(m_str, OleDbConn)
Dim cmd As New OleDbCommandBuilder(da)
OleDbConn.Open
da.Fill(dsDataSet, tbName)
dsDataSet.CaseSensitive = True
OleDbConn.Close()
End Sub

Note the "ByRef" in the sub statement, these are Reference objects not value
objects.

"Jon" wrote:
Hi,

I have a function to fill the data into the dataset:

Private Sub LoadSystemDataDB(ByVal m_str As String, ByVal da As _
OleDbDataAdapter, ByVal tbName As String)
Dim OleDbConn As New OleDbConnection(OLEDB_CONNECTION_1)
OleDbConn.Open()
da = New OleDbDataAdapter(m_str, OleDbConn)
Dim cmd As New OleDbCommandBuilder(da)
da.Fill(dsDataSet, tbName)
dsDataSet.CaseSensitive = True
OleDbConn.Close()
End Sub

However when i try to update the data using:
Dim autogen As New OleDbCommandBuilder(daLoginDetails)
daDataAdapter.Update(dsDataSet, "myTable")

I get error when i try to update it. The error is on the Update line where
it saids "The DataAdapter.SelectCommand property needs to be initialized".

So i guess i was doing something wrong when filling the data??
or what is the proper way to make a fill data function? as i have many
tables to load into the dataset.

Hope anyone can help?
many thanks.

Nov 21 '05 #9
Change Dim cmd As New OleDbCommandBuilder(da)
to cmd = new OleDbCommandBuilder(da)

The calling program should have the statements:

dim cb as OleDbCommandBuilder ' no NEW key word
Dim daDataAdapter as OleDbDataAdapter ' no NEW keyword
Public dsDataSet as New DataSet ' needs to go in front of this module so
that it's truely public

Call LoadSystemDataDB(sqlString, daDataAdapter, TblName, cb)
' after the call returns back to the caller
Dim OleDbConn As New OleDbConnection(OLEDB_CONNECTION_1)
daDataAdapter.Update(dsDataSet, "myTable")
OleDbConn.Close

The subroutine will create the NEW version of it.
Don't create another NEW version in the calling program you only want it
once.

I also assume that the dataset is a Public Object that was created in the
calling program.
"Jon" <Jo*@discussions.microsoft.com> wrote in message
news:43**********************************@microsof t.com...
ic, Thank you very much!

"Darrell Wesley" wrote:
Private Sub LoadSystemDataDB(ByVal m_str As String, ByRef da As _
OleDbDataAdapter, ByVal tbName As String, ByRef cmd as
OleDbCommandBuilder)
Dim OleDbConn As New OleDbConnection(OLEDB_CONNECTION_1)
da = New OleDbDataAdapter
da.SelectCommand = new OleDBCommand(m_str, OleDbConn)
Dim cmd As New OleDbCommandBuilder(da)
OleDbConn.Open
da.Fill(dsDataSet, tbName)
dsDataSet.CaseSensitive = True
OleDbConn.Close()
End Sub

Note the "ByRef" in the sub statement, these are Reference objects not
value
objects.

"Jon" wrote:
> Hi,
>
> I have a function to fill the data into the dataset:
>
> Private Sub LoadSystemDataDB(ByVal m_str As String, ByVal da As _
> OleDbDataAdapter, ByVal tbName As String)
> Dim OleDbConn As New OleDbConnection(OLEDB_CONNECTION_1)
> OleDbConn.Open()
> da = New OleDbDataAdapter(m_str, OleDbConn)
> Dim cmd As New OleDbCommandBuilder(da)
> da.Fill(dsDataSet, tbName)
> dsDataSet.CaseSensitive = True
> OleDbConn.Close()
> End Sub
>
> However when i try to update the data using:
> Dim autogen As New OleDbCommandBuilder(daLoginDetails)
> daDataAdapter.Update(dsDataSet, "myTable")
>
> I get error when i try to update it. The error is on the Update line
> where
> it saids "The DataAdapter.SelectCommand property needs to be
> initialized".
>
> So i guess i was doing something wrong when filling the data??
> or what is the proper way to make a fill data function? as i have many
> tables to load into the dataset.
>
> Hope anyone can help?
> many thanks.
>
>

Nov 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: hch | last post by:
dataAdapter.Update(data, "TableName") won’t work! I was about to deploy my first website on the Internet only to discover that the dataAdapter.Update() throws the Server Error in the third...
1
by: Galen Harris | last post by:
What's the best practice to use the dataadapter.update on a dataset that's been stored in session? We create a dataset on one page, and later in site, we want to call the dataadapter.update() to...
1
by: mivey4 | last post by:
Okay, The problem is that I have an Access Database that has the following fields: EmpID - Autonumber (PrimaryKey) AccountID - Text IssueReported - Memo DateOpened ...
2
by: johnb41 | last post by:
I have a very simple application where i just want to display records from a database, and be able to edit the records. Here's the code for the "update" button: Private Sub...
4
by: George | last post by:
Got a question about the side effect of DataAdapter.Update() and DataTable.GetChanges(). Say I set up a DataTable and a DataAdapter in a class. Delete (Not remove) a row in the data table and...
2
by: Rich | last post by:
Hello, Is there a way to capture the Records Affected count when performing a table Update on a Sql Server table using a DataAdapter? How is this done? Thanks, Rich
5
by: Emil | last post by:
I've created a very simple data base in Microsoft Access 2003. It consists of only one table called "Students" and it contains 2 information about each student: id-student and name. When I try...
3
by: Fred Chateau | last post by:
Any obvious reason here why data is not being loaded into the database? SqlDataAdapter dataAdapter = new SqlDataAdapter(sqlCommand); SqlCommandBuilder commandBuilder = new...
2
by: BobLewiston | last post by:
I can read in an SQL table ("Person.Contact") from AdventureWorks and step through it one row at a time, but when I try to save a record, either one I'm inserting or one I'm editting, I get the...
2
by: BobLewiston | last post by:
Some of you may have seen my earlier thread “PasswordHash NULL problem”. I’ve started a new thread because investigation has shown that the problem is actually quite different than I previously...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.