Click to See Complete Forum and Search --> : Updating Database Using DataViewGrid


ryansurrao
April 9th, 2008, 02:37 PM
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

jasonli
April 10th, 2008, 01:44 PM
You need an instance of class SQLCommandBuilder.