|
-
Mar 18th, 2011, 05:19 AM
#1
Thread Starter
Addicted Member
Data not Updated ?
i can't update my data at database
this my code :
VB.NET Code:
Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
Try
'Dim ds As New DataSet
Dim scmd As New OleDbCommand
If bAdd Then
scmd.CommandText = "insert into inv_t_products (prod_id,prod_name,unit,unitprice) " & _
"values(@prodid,@prodname,@unit,@unitprice)"
Else
'modify
scmd.CommandText = "update inv_t_products set prod_name=@prodname,unit=@unit,unitprice=@unitprice " & _
"where prod_id=@prodid"
End If
scmd.Parameters.Add(New OleDbParameter("@prodid", txtKd.Text))
scmd.Parameters.Add(New OleDbParameter("@prodname", txtNm.Text))
scmd.Parameters.Add(New OleDbParameter("@unit", txtSat.Text))
scmd.Parameters.Add(New OleDbParameter("@unitprice", txtHarga.Text))
scmd.Connection = dbConn
scmd.ExecuteNonQuery()
bUpdated = True
Me.Close()
Catch ex As Exception
ERRDesc(ex)
End Try
MsgBox("Saved", MsgBoxStyle.Information)
End Sub
i have problem when update data, data not updated.
how the solution ?
thank you
-
Mar 18th, 2011, 07:03 AM
#2
Re: Data not Updated ?
ExecuteNonQuery returns an integer value indicating how many rows has been affected by the command. See what it is:
Code:
Dim rowsaffected As Integer = scmd.ExecuteNonQuery()
MsgBox("Rows affected:" & rowsaffected.ToString())
Also I didn't see where dbconn connection is opened in your code.
Are you sure it stays open?
Code:
If dbconn.State <> ConnectionState.Open Then dbconn.Open()
-
Mar 18th, 2011, 07:04 AM
#3
Re: Data not Updated ?
How EXACTLY do you know that data isn't saved? When you try to save data, there are only three possibilities:
1. There are changes to save, they are saved successfully and ExecuteNonQuery returns a non-zero value.
2. There are no changes to save so ExecuteNonQuery returns zero.
3. An exception is thrown.
Which is it in your case? If it's not 2 or 3 then the data IS being saved and you're just looking in the wrong place or at the wrong time. In that case, follow the first link in my signature.
Last edited by jmcilhinney; Mar 18th, 2011 at 07:06 AM.
Reason: Changed Update to ExecuteNonQuery
-
Mar 18th, 2011, 09:25 AM
#4
Thread Starter
Addicted Member
Re: Data not Updated ?
thank you for your replay.
i tried check connection state and the result is 1 (Open)
and when i try this code :
Code:
Dim rowsaffected As Integer = scmd.ExecuteNonQuery()
MsgBox("Rows affected:" & rowsaffected.ToString())
the result is 0
-
Mar 18th, 2011, 09:49 AM
#5
Thread Starter
Addicted Member
Re: Data not Updated ?
I've got the solution, I changed my code to:
Code:
scmd.CommandText = "update inv_t_products set prod_name=@prodname,unit=@unit,unitprice=@unitprice " & _
"where prod_id='" & txtKd.Text & "'"
-
Mar 18th, 2011, 09:57 AM
#6
New Member
Re: Data not Updated ?
yes the solution is correct
Rocky (rocks the world)
Reliable and trustable Hyip investment Monitoring and advertising service http://www.TheBig1.Tk
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|