Database wont update but getting no errors....

G

Guest

Not sure what the problem is here... Trying to update from a datagrid to an
access database using vb.net... Its not updating the database but Im not
getting any errors... Here is my code...

'OleDbUpdateCommand1

Me.OleDbUpdateCommand1.CommandText = "UPDATE tblGifts SET gift = ?,
name = ?, purchased = ? WHERE (autonum = ?) AND (gi" & _
"ft = ? OR ? IS NULL AND gift IS NULL) AND (name = ? OR ? IS NULL
AND name IS NUL" & _
"L) AND (purchased = ?)"
Me.OleDbUpdateCommand1.Connection = Me.OleDbConnection1
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("gift",
System.Data.OleDb.OleDbType.VarWChar, 50, "gift"))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("name",
System.Data.OleDb.OleDbType.VarWChar, 50, "name"))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("purchased",
System.Data.OleDb.OleDbType.Boolean, 2, "purchased"))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_autonum",
System.Data.OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input,
False, CType(0, Byte), CType(0, Byte), "autonum",
System.Data.DataRowVersion.Original, Nothing))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_gift",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"gift", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_gift1",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"gift", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_name",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"name", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_name1",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"name", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_purchased",
System.Data.OleDb.OleDbType.Boolean, 2, System.Data.ParameterDirection.Input,
False, CType(0, Byte), CType(0, Byte), "purchased",
System.Data.DataRowVersion.Original, Nothing))

--------------------------------------------------------------------------

Sub dgGifts_Update(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)
Dim ckPurchased As CheckBox = CType(e.Item.FindControl("CheckBox1"),
CheckBox)
Me.OleDbConnection1.Open()
daGifts.Update(DsGifts1)
Me.OleDbConnection1.Close()
dgGifts.EditItemIndex = -1
daGifts.Fill(DsGifts1)
dgGifts.DataBind()
End Sub
 
J

james

I see where you are telling the DataAdaptor to Update: daGifts.Update(DsGifts1) < I'm assuming DsGifts1 is your Dataset>
But, you are not telling it which Table to update: daGifts.Update(DsGifts1,"tblGifts") < and I assume that tblGifts is the
table you want to update.>
That appears to me to be the problem. Although, I would think it would throw an error if you doin't specify the table to apply
the update to.
james
 
C

Cor Ligthert

Brett,

Are you sure there is something to update.

Standard you can write
if DSGifts1.haschanges then
daGifts.Fill(DsGifts1)
end if

Than you can as well easily debug that.

I hope this helps?

Cor
 
G

Guest

Hmmm.... It makes sense to me that the table would have to be included, but
it still does the same thing. Per Cors comment, it looks like there may not
be anything to update cause when using his code it doesnt fill the dataset
again... I dont understand why though, cause I AM making a change to the
datagrid.... Any ideas??



james said:
I see where you are telling the DataAdaptor to Update: daGifts.Update(DsGifts1) < I'm assuming DsGifts1 is your Dataset>
But, you are not telling it which Table to update: daGifts.Update(DsGifts1,"tblGifts") < and I assume that tblGifts is the
table you want to update.>
That appears to me to be the problem. Although, I would think it would throw an error if you doin't specify the table to apply
the update to.
james
 
C

Cor Ligthert

Brett,

I saw but have not the idea you showed where/how you did the update of items
in the rows of a table in the dataset.

The most known problem is that the data is not yet forced in the datset
because of a row change (currencymanager), that you can do with

BindingContext(ds.Tables(0)).EndCurrentEdit()

I hope this helps a little bit?

Cor
 
G

Guest

Im not sure I know what you mean. Im fairly new to .NET, so you'll have to
bear with my ignorance. :) Shouldnt the dataset be updated because of the
update parameters ?
 
C

Cor Ligthert

Brett
Im not sure I know what you mean. Im fairly new to .NET, so you'll have to
bear with my ignorance. :) Shouldnt the dataset be updated because of the
update parameters ?
Yes the should, however there should be data to update.

Do you know the commandbuilder by the way, for the not to difficult select
statements (less than 100 fields and no joins) it makes mostly your
commands.

dim cmb as new commandbuilder(da)
http://msdn.microsoft.com/library/d.../html/cpconautomaticallygeneratedcommands.asp

I hope this helps?

Cor
 

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