By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,805 Members | 1,296 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,805 IT Pros & Developers. It's quick & easy.

Update

OuTCasT
100+
P: 374
Can someone please tell me how does a person use a commandbuilder to update a dataset so that i can update the table in the database.


Expand|Select|Wrap|Line Numbers
  1. sqlEarningsCommand = New SqlCommand("Select * from earnings order by EmployeeID", sqlConnection)
  2.         sqlEarningsAdapter = New SqlDataAdapter(sqlEarningsCommand)
  3.         sqlEarningsDatatable = New DataTable
  4.         sqlEarningsAdapter.Fill(sqlEarningsDatatable)
  5.  
  6.         lblEarnings_temp.DataBindings.Add("text", sqlEarningsDatatable, "EmployeeID")
  7.         lblEarningsTotal.DataBindings.Add("text", sqlEarningsDatatable, "EarningTotal")
  8.         txtAnnualSalary.DataBindings.Add("text", sqlEarningsDatatable, "AnnualSalary")
  9.         lblNetTotal.DataBindings.Add("text", sqlEarningsDatatable, "NetSalarytotal")
  10.  
  11.         Dim x As Integer
  12.         For x = 1 To 14
  13.             mtxtEarnings(x).DataBindings.Add("text", sqlEarningsDatatable, x.ToString)
  14.         Next
  15.  
  16.         sqlmanager2 = DirectCast(Me.BindingContext(sqlEarningsDatatable), CurrencyManager)

button click event.

Expand|Select|Wrap|Line Numbers
  1. sqlConnection.Open()
  2.  sqlmanager2.EndCurrentEdit()
  3. Dim sqlEmployeeDetailsUpdate As New SqlCommandBuilder(sqlAdapter)
  4. Try
  5.             sqlAdapter.Update(sqlDataTable)
  6. catch 
  7. end try
that works find for the datatable, i need to update a dataset cause i aint using a datatable.....
Jun 19 '08 #1
Share this Question
Share on Google+
1 Reply


jeffstl
Expert 100+
P: 432
I am not sure what your specific issue is. If you need to update use UPDATE SQL.

Expand|Select|Wrap|Line Numbers
  1.  
  2. sqlEarningsCommand = New SqlCommand("UPDATE Earnings set EmployeeName = '" & strEmpName & "',EmployeeAddress = '" & strEmpAddress & "' where EmployeeID = " & strEmpID & "", sqlConnection)
  3.  
  4.  
  5.  
  6.  
Jun 19 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.