943,522 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 2928
  • VB.NET RSS
May 25th, 2008
0

update sqlce commandbuilder

Expand Post »
I am trying to learn VB .NET again. Have not used in a long time. I have bound my controls to my datatable and then I put values into the controls, I then have a button that I am trying to get to add/update the rows to the database. It acts like it works fine no errors or anything, but whn I look at the table data after the update, it is all null... ugg.. can someone please look at my code and tell me what I am doing wrong?

VB.NET Syntax (Toggle Plain Text)
  1. Dim conn As SqlCeConnection
  2. Dim da As SqlCeDataAdapter
  3. Dim dtAcct As New DataTable("Account")
  4. Dim dtAcctType As New DataTable("AccountType")
  5.  
  6.  
  7. Private Sub frmAccount_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  8. Dim cmd As New System.Data.SqlServerCe.SqlCeCommand
  9. Dim cmd1 As String = "SELECT * FROM Account"
  10. Dim da2 As New SqlCeDataAdapter
  11.  
  12. conn = New SqlCeConnection("Data Source=C:\Documents and Settings\Owner\Desktop\Finances\HomeComplete\Databases\HomeComplete.sdf")
  13.  
  14.  
  15. conn.Open()
  16. cmd.Connection = conn
  17. da = New SqlCeDataAdapter(cmd1, conn)
  18. Dim cmdBuild As SqlCeCommandBuilder = New SqlCeCommandBuilder(da)
  19. da.Fill(dtAcct)
  20. cmd.CommandText = "SELECT * FROM AccountType"
  21. da2 = New SqlCeDataAdapter(cmd)
  22. da2.Fill(dtAcctType)
  23.  
  24. txtAcctName.DataBindings.Add("Text", dtAcct, "AcctName")
  25. txtPhone.DataBindings.Add("Text", dtAcct, "AcctPh")
  26. dtOpenDate.DataBindings.Add("Text", dtAcct, "AcctOpenDate")
  27. dtCloseDate.DataBindings.Add("Text", dtAcct, "AcctCloseDate")
  28. chkActive.DataBindings.Add("checked", dtAcct, "AcctActive")
  29. txtWeb.DataBindings.Add("Text", dtAcct, "AcctWebAddress")
  30. txtID.DataBindings.Add("Text", dtAcct, "AcctWebID")
  31. txtPW.DataBindings.Add("Text", dtAcct, "AccteWebPWord")
  32. txt1.DataBindings.Add("Text", dtAcct, "AcctBillAddr1")
  33. txt2.DataBindings.Add("Text", dtAcct, "AcctBillAddr2")
  34. txtCity.DataBindings.Add("Text", dtAcct, "AcctBillCity")
  35. txtSt.DataBindings.Add("Text", dtAcct, "AcctBillSt")
  36. txtZip.DataBindings.Add("Text", dtAcct, "AcctBillZip")
  37. cboType.DataSource = dtAcctType
  38. cboType.DisplayMember = "AcctType"
  39. cboType.ValueMember = "AcctTypeID"
  40. cboType.DataBindings.Add("SelectedValue", dtAcct, "AcctTypeID")
  41.  
  42.  
  43. End Sub
  44.  
  45.  
  46. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  47. Try
  48. conn.Open()
  49. Catch
  50. End Try
  51.  
  52. Dim cmd1 As String = "SELECT * FROM Account"
  53. da = New SqlCeDataAdapter(cmd1, conn)
  54. Dim cmdBuild As SqlCeCommandBuilder = New SqlCeCommandBuilder(da)
  55. da.UpdateCommand = cmdBuild.GetUpdateCommand
  56. da.InsertCommand = cmdBuild.GetInsertCommand
  57. da.DeleteCommand = cmdBuild.GetDeleteCommand
  58. da.Update(dtAcct)
  59.  
  60.  
  61. End Sub
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
cpopham is offline Offline
65 posts
since Mar 2005
Nov 18th, 2008
0

Re: update sqlce commandbuilder

Hi All,

Has anyone figured this out? I currently have the same issue, when I attempt an INSERT INTO or UPDATE it updates a dataset and not the SQL CE Server itself.

Any help is appreciated.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
WaterboyVB is offline Offline
1 posts
since Nov 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: how to modify an exe without preparing a setup afresh
Next Thread in VB.NET Forum Timeline: Program ideas





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC