Cannot do update on a record. Please help.

G

Guest

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.
 
C

Cor Ligthert

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
 
G

Guest

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
 
G

Guest

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 said:
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 said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top