update sqlce commandbuilder

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2005
Posts: 65
Reputation: cpopham is an unknown quantity at this point 
Solved Threads: 0
cpopham cpopham is offline Offline
Junior Poster in Training

update sqlce commandbuilder

 
0
  #1
May 25th, 2008
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?

  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
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 1
Reputation: WaterboyVB is an unknown quantity at this point 
Solved Threads: 0
WaterboyVB WaterboyVB is offline Offline
Newbie Poster

Re: update sqlce commandbuilder

 
0
  #2
Nov 18th, 2008
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC