CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2008
    Posts
    1

    Updating Database Using DataViewGrid

    Hi

    I have a couple of datagrids that need updating. I was able to populate the data into the grid, but I dont know what needs to be done post updation. For Some reason it doesnt update. The code snippet is given below.

    Thanks is advance. I would also like to know if the approach I am taking is good or not.

    Imports System
    Imports System.Drawing
    Imports System.Collections
    Imports System.ComponentModel
    Imports System.Windows.Forms
    Imports System.Data
    Imports System.Data.SqlClient
    Public Class NetworkInventory

    Public DeviceMasterDeviceId As String

    Private Sub ViewDevicesMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ViewDevicesMenu.Click

    Dim SQLConnectionString As String = "server=jba118926pc\sql2005;initial catalog=NetOps;integrated security = true"
    Dim SQLConnection As New SqlConnection(SQLConnectionString)
    Dim SQLQuery As String = "Select * from DeviceMasterList"
    Dim SQLAdapter As New SqlDataAdapter(SQLQuery, SQLConnection)
    SQLAdapter.SelectCommand.CommandType = CommandType.Text

    Dim SQLDS As New DataSet()
    SQLAdapter.Fill(SQLDS)
    dgDeviceMaster.DataSource = SQLDS.Tables(0).DefaultView
    dgDeviceMaster.ReadOnly = True

    End Sub

    Private Sub dgDeviceMaster_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgDeviceMaster.CellDoubleClick

    'MsgBox(dgDeviceMaster.CurrentCell.Value.ToString)

    'MsgBox(dgDeviceMaster.CurrentCell.DataGridView(0, dgDeviceMaster.CurrentCellAddress.Y).Value)

    DeviceMasterDeviceId = dgDeviceMaster.CurrentCell.DataGridView(0, dgDeviceMaster.CurrentCellAddress.Y).Value

    Dim SQLConnectionString As String = "server=jba118926pc\sql2005;initial catalog=NetOps;integrated security = true"
    Dim SQLConnection As New SqlConnection(SQLConnectionString)
    Dim SQLQuery As String = "Select * from DeviceMasterList where DeviceID = " & DeviceMasterDeviceId
    Dim SQLAdapter As New SqlDataAdapter(SQLQuery, SQLConnection)
    SQLAdapter.SelectCommand.CommandType = CommandType.Text

    Dim SQLDS As New DataSet()
    SQLAdapter.Fill(SQLDS)
    dgUpdateDeviceMaster.DataSource = SQLDS.Tables(0).DefaultView
    dgUpdateDeviceMaster.ReadOnly = False

    End Sub


    Private Sub UpdateDevicesMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UpdateDevicesMenu.Click



    End Sub

  2. #2
    Join Date
    Dec 2005
    Location
    Waterloo ON
    Posts
    545

    Re: Updating Database Using DataViewGrid

    You need an instance of class SQLCommandBuilder.
    The difficulty is that you have no idea how difficult it is.

    .Net 3.5/VS 2008

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured