PC Review


Reply
Thread Tools Rate Thread

Cannot do update on a record. Please help.

 
 
=?Utf-8?B?TmV3Ymll?=
Guest
Posts: n/a
 
      25th Feb 2005
I am VERY NEW this whole concept of DataSet and all. I have a code that goes
like this..
=============================================
conn.Open()
Dim ds = New Data.DataSet

'/// The function below is used to create adapter ///
da = CreateCmdsAndUpdate(mySelectQuery, myUpdate, conn)

da.Fill(ds, myTableName)
da.Update(ds, myTableName)
conn.Close()

========================================

Here are my questions to you.
1) I ran it without any error, but update did not take place to the record.
What else could be missing here?

2) Why is Fill method required before Update method? When I tried
commenting out 'da.Fill(ds, myTableName)' and ran the code, it gave me an
error "Update unable to find TableMapping or DataTable [table_name]".

3) Seems like I am updating the whole table, but I indeed only want to
update one row. Is there a better way?

I have been browsing for answer for days and seeing different pieces of
information here and there, but cannot put together the puzzle. If you can
recommend me a good booking regarding making SELECT, UPDATE, INSERT, and
DELETE transactions via ADO.NET, I will greatly appreciate it. Thank you
very much for your time enlightening me.



 
Reply With Quote
 
 
 
 
Cor Ligthert
Guest
Posts: n/a
 
      25th Feb 2005
Newbie,

I never saw your kind of code code however I can use it to simple explain it
to you.

> conn.Open()
> Dim ds = New Data.DataSet
>
> '/// The function below is used to create adapter ///
> da = CreateCmdsAndUpdate(mySelectQuery, myUpdate, conn)
>
> da.Fill(ds, myTableName)


'Do the changes in the dataset

> da.Update(ds, myTableName)
> conn.Dispose()
>


(This is not the normal way only to make it clear and assuming you used the
dataadapter wizard to create that.)

I hope this helps?

Cor




 
Reply With Quote
 
=?Utf-8?B?RG90TmV0SmVyb21l?=
Guest
Posts: n/a
 
      25th Feb 2005
Hi Newbieeeeeeeeeee,

Answers for your questions...

1. Your code might have run ....but have u did any modifications to your
records inside the dataset ( I don't find any code for that in your code snap)

2. Yes, Fill method is required.... By this method only you ae getting the
records from your database into the Dataset.

3. When you are updating the database with the update method...only records
got modified into the dataset will be updated ..not entire database.

Cheers,

Jerome. M

"Newbie" wrote:

> I am VERY NEW this whole concept of DataSet and all. I have a code that goes
> like this..
> =============================================
> conn.Open()
> Dim ds = New Data.DataSet
>
> '/// The function below is used to create adapter ///
> da = CreateCmdsAndUpdate(mySelectQuery, myUpdate, conn)
>
> da.Fill(ds, myTableName)
> da.Update(ds, myTableName)
> conn.Close()
>
> ========================================
>
> Here are my questions to you.
> 1) I ran it without any error, but update did not take place to the record.
> What else could be missing here?
>
> 2) Why is Fill method required before Update method? When I tried
> commenting out 'da.Fill(ds, myTableName)' and ran the code, it gave me an
> error "Update unable to find TableMapping or DataTable [table_name]".
>
> 3) Seems like I am updating the whole table, but I indeed only want to
> update one row. Is there a better way?
>
> I have been browsing for answer for days and seeing different pieces of
> information here and there, but cannot put together the puzzle. If you can
> recommend me a good booking regarding making SELECT, UPDATE, INSERT, and
> DELETE transactions via ADO.NET, I will greatly appreciate it. Thank you
> very much for your time enlightening me.
>
>
>

 
Reply With Quote
 
=?Utf-8?B?TmV3Ymll?=
Guest
Posts: n/a
 
      25th Feb 2005
You are right. I don't think I have modified my record within DataSet. But,
how do I do that, do you have any sample code that I can learn from?

This is the detail within 'CreateCmdsAndUpdate' function used to create
DataAdapter. There is a line saying ' Code to modify data in DataSet here',
and that's where I do not know what to do with it..

Please forgive my ignorance, and I am really trying hard to learn this.
THANK YOU!


===================================
Public Function CreateCmdsAndUpdate(ByVal mySelectQuery As String, ByVal
myUpdate As String, ByVal myConnection As OleDb.OleDbConnection) As
OleDb.OleDbDataAdapter

Dim da As New OleDb.OleDbDataAdapter
'da.SelectCommand = New OleDb.OleDbCommand(mySelectQuery,
myConnection)
Dim cmd As OleDb.OleDbCommand
Dim parm As OleDb.OleDbParameter

'Dim custCB As OleDb.OleDbCommandBuilder = New
OleDb.OleDbCommandBuilder(da)

cmd = New OleDb.OleDbCommand(mySelectQuery, myConnection)

cmd.Parameters.Add(TextBox1.Text, OleDb.OleDbType.VarChar, 30)
cmd.Parameters.Add(TextBox2.Text, OleDb.OleDbType.VarChar, 30)
cmd.Parameters.Add(TextBox3.Text, OleDb.OleDbType.VarChar, 30)
da.SelectCommand = cmd


' Code to modify data in DataSet here

cmd = New OleDb.OleDbCommand(myUpdate, myConnection)
cmd.Parameters.Add(TextBox1.Text, OleDb.OleDbType.VarChar, 30,
"list_name")
cmd.Parameters.Add(TextBox2.Text, OleDb.OleDbType.VarChar, 30,
"output_file")
cmd.Parameters.Add(TextBox3.Text, OleDb.OleDbType.VarChar, 30,
"printers")
cmd.Parameters.Add(TextBox4.Text, OleDb.OleDbType.VarChar, 30,
"location")
parm = cmd.Parameters.Add(TextBox5.Text, OleDb.OleDbType.VarChar,
30, "nmh_comment")
parm.SourceVersion = DataRowVersion.Original

da.UpdateCommand = cmd

Return da
End Function 'SelectOleDbSrvRows

End Class
===================================

"DotNetJerome" wrote:

> Hi Newbieeeeeeeeeee,
>
> Answers for your questions...
>
> 1. Your code might have run ....but have u did any modifications to your
> records inside the dataset ( I don't find any code for that in your code snap)
>
> 2. Yes, Fill method is required.... By this method only you ae getting the
> records from your database into the Dataset.
>
> 3. When you are updating the database with the update method...only records
> got modified into the dataset will be updated ..not entire database.
>
> Cheers,
>
> Jerome. M
>
> "Newbie" wrote:
>
> > I am VERY NEW this whole concept of DataSet and all. I have a code that goes
> > like this..
> > =============================================
> > conn.Open()
> > Dim ds = New Data.DataSet
> >
> > '/// The function below is used to create adapter ///
> > da = CreateCmdsAndUpdate(mySelectQuery, myUpdate, conn)
> >
> > da.Fill(ds, myTableName)
> > da.Update(ds, myTableName)
> > conn.Close()
> >
> > ========================================
> >
> > Here are my questions to you.
> > 1) I ran it without any error, but update did not take place to the record.
> > What else could be missing here?
> >
> > 2) Why is Fill method required before Update method? When I tried
> > commenting out 'da.Fill(ds, myTableName)' and ran the code, it gave me an
> > error "Update unable to find TableMapping or DataTable [table_name]".
> >
> > 3) Seems like I am updating the whole table, but I indeed only want to
> > update one row. Is there a better way?
> >
> > I have been browsing for answer for days and seeing different pieces of
> > information here and there, but cannot put together the puzzle. If you can
> > recommend me a good booking regarding making SELECT, UPDATE, INSERT, and
> > DELETE transactions via ADO.NET, I will greatly appreciate it. Thank you
> > very much for your time enlightening me.
> >
> >
> >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
adding a new record at subform should update an existing record (not create new record) Mark Kubicki Microsoft Access Form Coding 1 16th Jan 2009 08:34 AM
Update Master records (swap / replace old record from new record) in two file tarone@gmail.com Microsoft Excel Discussion 1 9th Dec 2006 03:28 PM
Dataset update error (record requires parent table record) PAUL Microsoft ADO .NET 4 5th Oct 2005 03:46 PM
Dataset update error (record requires parent table record) PAUL Microsoft VB .NET 3 5th Oct 2005 03:35 PM
Re: Update current record information to a separate record status reco Jeff Boyce Microsoft Access Forms 5 6th Aug 2004 01:23 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:27 AM.