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

Update SQL table with Dataset

OuTCasT
100+
P: 374
can some please tell me how to update a table with data from a dataset

what ive done is fill the dataset with the adapter and used a for Next loop to step into each row and display it into text boxes on the form.
on the save button

Expand|Select|Wrap|Line Numbers
  1. Dim sqlCon As SqlConnection = New SqlConnection("Server=(local);Data Source=.\SQLEXPRESS;Initial Catalog=Payday10;Integrated Security=True;Pooling=False")
  2.     Dim daEmployee As New SqlDataAdapter("select * from EarningsNew order by emplCode", sqlCon)
  3.     Dim dsEarningDescription As New DataSet("PayDay10")
  4.  
  5. Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  6.         sqlCon.Open()
  7.  
  8.         daEmployee.FillSchema(dsEarningDescription, SchemaType.Source, "EarningsNew")
  9.         daEmployee.Fill(dsEarningDescription, "EarningsNew")
  10.  
  11.         Dim x As Integer
  12.         For x = dsEarningDescription.Tables(0).Rows.Count - 1 To 0 Step -1
  13.             TextBox1.Text = dsEarningDescription.Tables(0).Rows(x).Item("EarnFixed").ToString
  14.         Next
  15.         For x = dsEarningDescription.Tables(0).Rows.Count - 1 To 1 Step -1
  16.             TextBox2.Text = dsEarningDescription.Tables(0).Rows(x).Item("EarnFixed").ToString
  17.         Next
  18.         For x = dsEarningDescription.Tables(0).Rows.Count - 1 To 2 Step -1
  19.             TextBox3.Text = dsEarningDescription.Tables(0).Rows(x).Item("EarnFixed").ToString
  20.         Next
  21.         For x = dsEarningDescription.Tables(0).Rows.Count - 1 To 3 Step -1
  22.             TextBox4.Text = dsEarningDescription.Tables(0).Rows(x).Item("EarnFixed").ToString
  23.         Next
  24.         For x = dsEarningDescription.Tables(0).Rows.Count - 1 To 4 Step -1
  25.             TextBox5.Text = dsEarningDescription.Tables(0).Rows(x).Item("EarnFixed").ToString
  26.         Next
  27.         For x = dsEarningDescription.Tables(0).Rows.Count - 1 To 5 Step -1
  28.             TextBox6.Text = dsEarningDescription.Tables(0).Rows(x).Item("EarnFixed").ToString()
  29.         Next
  30.         For x = dsEarningDescription.Tables(0).Rows.Count - 1 To 6 Step -1
  31.             TextBox7.Text = dsEarningDescription.Tables(0).Rows(x).Item("EarnFixed").ToString
  32.         Next
  33.         For x = dsEarningDescription.Tables(0).Rows.Count - 1 To 7 Step -1
  34.             TextBox8.Text = dsEarningDescription.Tables(0).Rows(x).Item("EarnFixed").ToString
  35.         Next
  36.     End Sub
  37.  
  38.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  39.         Dim sqlCommandBuilder As New SqlCommandBuilder(daEmployee)
  40.         daEmployee.Update(dsEarningDescription, "EarningsNew")
  41.  
  42.     End Sub
Jun 19 '08 #1
Share this question for a faster answer!
Share on Google+

Post your reply

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