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

how to update data using datagridview in vb.net

P: 40
Hi
i want to update data in database using datagridview
actually i am displaying the data in datagridview and after that i want to update some rows data directly modifying the displayed data into the datagridview

how can be done like this
please send me some code or some help

regards
varinder sharma
Apr 30 '09 #1
Share this Question
Share on Google+
1 Reply


OuTCasT
100+
P: 374
Expand|Select|Wrap|Line Numbers
  1. Dim sqlConnection As SqlConnection
  2.     Dim sqlCommandArea As SqlCommand
  3.     Dim sqlAdapterArea As SqlDataAdapter
  4.     Dim sqlDataTableArea As DataTable
  5.     Dim sqlManagerArea As CurrencyManager
  6.  
  7.  sqlCommandArea = New SqlCommand("SELECT * FROM AreaDescriptions order by AreaCode", sqlConnection)
  8.         sqlAdapterArea = New SqlDataAdapter
  9.         sqlAdapterArea.SelectCommand = sqlCommandArea
  10.         sqlDataTableArea = New DataTable
  11.         sqlAdapterArea.Fill(sqlDataTableArea)
  12.         'Bind Controls with datatable
  13.         txtCodeArea.DataBindings.Add("text", sqlDataTableArea, "AreaCode", True)
  14.         txtDescriptionArea.DataBindings.Add("text", sqlDataTableArea, "AreaDescription", True)
  15.         txtReferenceNoArea.DataBindings.Add("text", sqlDataTableArea, "AreaReferenceNo", True)
  16.         txtCostingCodeArea.DataBindings.Add("text", sqlDataTableArea, "AreaCostingCode", True)
  17.         txtGLDebitCodeArea.DataBindings.Add("text", sqlDataTableArea, "AreaGLDebit", True)
  18.         txtGLCreditCodeArea.DataBindings.Add("text", sqlDataTableArea, "AreaGLCredit", True)
  19.         'Set Gridview
  20.         AreaGridView.DataSource = sqlDataTableArea
  21.         ' Establish Navigation Manager
  22.         sqlManagerArea = DirectCast(Me.BindingContext(sqlDataTableArea), CurrencyManager)
  23.  
  24. Private Sub Save()
  25.         Try
  26.             sqlConnection.Open()
  27.             sqlManagerArea.EndCurrentEdit()
  28.             Dim sqlAreaUpdate As New SqlCommandBuilder(sqlAdapterArea)
  29.             sqlAdapterArea.Update(sqlDataTableArea)
  30.             sqlConnection.Close()
  31.  
  32.         Catch sqlexc As SqlException
  33.             MsgBox(sqlexc.Message, MsgBoxStyle.OkOnly, "SQL Exception Error")
  34.         Catch exc As Exception
  35.             MsgBox(exc.Message, MsgBoxStyle.OkOnly, "Connection Failed")
  36.         End Try
  37.  
  38.     End Sub
Apr 30 '09 #2

Post your reply

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