Visual Basic.NET - Update Dataset

 
Vista:

Update Dataset

Publicado por NESTOR (8 intervenciones) el 19/03/2007 17:22:49
Hola gente.
Tengo un problema.
Tengo un datagrid que utilizo para cargar la tabla "Cliente". Pero no me esta funcionando el update de la tabla "Cliente".

Muchas gracias!!!

'*****************INICIO CODIGO******************
Imports System.Data.SqlClient
Imports System.Data
Public Class Clientes
Inherits System.Windows.Forms.Form
Dim DS As DataSet
Dim hileradeconeccion As String = "workstation id=YODAS;packet size=4096;integrated security=SSPI;data source=YODAS;persist security info=False;initial catalog=VENDEDOR"
Dim connection As SqlConnection = New SqlConnection(hileradeconeccion)
Dim Adapter As New SqlDataAdapter("Select * from Cliente", connection)

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents Button6 As System.Windows.Forms.Button
Friend WithEvents Button5 As System.Windows.Forms.Button
Friend WithEvents DataGrid3 As System.Windows.Forms.DataGrid
Friend WithEvents Cerrar As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Clientes))
Me.GroupBox1 = New System.Windows.Forms.GroupBox
Me.Button6 = New System.Windows.Forms.Button
Me.Button5 = New System.Windows.Forms.Button
Me.DataGrid3 = New System.Windows.Forms.DataGrid
Me.Cerrar = New System.Windows.Forms.Button
Me.GroupBox1.SuspendLayout()
CType(Me.DataGrid3, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'GroupBox1
'
Me.GroupBox1.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.GroupBox1.Controls.Add(Me.Button6)
Me.GroupBox1.Controls.Add(Me.Button5)
Me.GroupBox1.Controls.Add(Me.DataGrid3)
Me.GroupBox1.Location = New System.Drawing.Point(16, 16)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(856, 248)
Me.GroupBox1.TabIndex = 14
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "CLIENTES"
'
'Button6
'
Me.Button6.Location = New System.Drawing.Point(696, 208)
Me.Button6.Name = "Button6"
Me.Button6.Size = New System.Drawing.Size(72, 32)
Me.Button6.TabIndex = 2
Me.Button6.Text = "CLIENTES"
'
'Button5
'
Me.Button5.Location = New System.Drawing.Point(768, 208)
Me.Button5.Name = "Button5"
Me.Button5.Size = New System.Drawing.Size(72, 32)
Me.Button5.TabIndex = 1
Me.Button5.Text = "UPDATE"
'
'DataGrid3
'
Me.DataGrid3.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.DataGrid3.DataMember = ""
Me.DataGrid3.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.DataGrid3.Location = New System.Drawing.Point(8, 16)
Me.DataGrid3.Name = "DataGrid3"
Me.DataGrid3.Size = New System.Drawing.Size(840, 184)
Me.DataGrid3.TabIndex = 0
'
'Cerrar
'
Me.Cerrar.BackColor = System.Drawing.Color.FromArgb(CType(128, Byte), CType(128, Byte), CType(255, Byte))
Me.Cerrar.ForeColor = System.Drawing.Color.FromArgb(CType(224, Byte), CType(224, Byte), CType(224, Byte))
Me.Cerrar.Image = CType(resources.GetObject("Cerrar.Image"), System.Drawing.Image)
Me.Cerrar.ImageAlign = System.Drawing.ContentAlignment.TopCenter
Me.Cerrar.Location = New System.Drawing.Point(800, 288)
Me.Cerrar.Name = "Cerrar"
Me.Cerrar.Size = New System.Drawing.Size(48, 40)
Me.Cerrar.TabIndex = 15
Me.Cerrar.Text = "Cerrar"
Me.Cerrar.TextAlign = System.Drawing.ContentAlignment.BottomCenter
'
'Clientes
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(880, 342)
Me.Controls.Add(Me.Cerrar)
Me.Controls.Add(Me.GroupBox1)
Me.Name = "Clientes"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "Clientes"
Me.GroupBox1.ResumeLayout(False)
CType(Me.DataGrid3, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub Cerrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cerrar.Click
Me.Close()
End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Try

Dim conn As SqlCommand = New SqlCommand

DS = New DataSet("CLIENTE")

Adapter.TableMappings.Add("Table", "CLIENTE")
Adapter.Fill(DS)

DataGrid3.DataSource = DS

Catch ex As Exception
MessageBox.Show(ex.Message + vbLf + ex.StackTrace)
End Try
End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Try
' Check for changes with the HasChanges method first.
If Not DS.HasChanges(DataRowState.Modified) Then Exit Sub
' Create temporary DataSet variable.
Dim xDataSet As DataSet
' GetChanges for modified rows only.
xDataSet = DS.GetChanges(DataRowState.Modified)
' Check the DataSet for errors.
If xDataSet.HasErrors Then
Exit Sub
' Insert code to resolve errors.
End If
' After fixing errors, update the data source with the DataAdapter
' used to create the DataSet.
Adapter.Update(xDataSet)
Catch ex As Exception
MessageBox.Show(ex.Message + vbLf + ex.StackTrace)
End Try
End Sub
End Class
'***************************************************************FIN CODIGO**********
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder