Visual Basic.NET - ¡No me guarda los datos!

 
Vista:

¡No me guarda los datos!

Publicado por Roberto (1 intervención) el 10/11/2010 20:11:19
Saludos a todos.

Tengo el código que expongo a continuación. Todo va bien, excepto en el momento de grabar las modificaciones o los registros nuevos. En ese caso pierdo todo lo que he introducido. ¿Alguien sabría como solventar este problema? Estoy haciendo servir Visual Basic 2005 Express contra una base de datos Microsoft Access 2000. Muchas gracias a todos.

Imports System.data
Imports System.data.SqlClient
Imports System.ComponentModel
Imports PAY.ClsGenerica
Imports Microsoft.Office.Interop.Access

Public Class frmBancos
Private EmployeesBindingSource As BindingSource

Public Sub New()

InitializeComponent()

EmployeesBindingSource = New BindingSource()
EmployeesBindingSource.AllowNew = True

End Sub

Private Sub frmBancos_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim ds As DataSet = RetrieveDataSet()
If ds IsNot Nothing Then

' Associate the DataSet with the BindingSource.
Me.EmployeesBindingSource.DataMember = "Bancos"
Me.EmployeesBindingSource.DataSource = ds

Me.EmployeesBindingNavigator.BindingSource = Me.EmployeesBindingSource

Me.employeeIDTextBox.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.EmployeesBindingSource, "Num_banc", True))
Me.titleTextBox.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.EmployeesBindingSource, "Nom_banc", True))
End If
End Sub

Public Function RetrieveDataSet() As DataSet
Dim clase As New ClsGenerica
Try

Dim connectStringBuilder As New OleDb.OleDbConnectionStringBuilder()
connectStringBuilder.DataSource = "Impagados"
connectStringBuilder.ConnectionString = clase.conec

Dim ds As New DataSet("Bancos")

Using connection As New OleDb.OleDbConnection(connectStringBuilder.ConnectionString)

connection.Open()

Dim command As New OleDb.OleDbCommand( _
"SELECT TOP 100 * FROM Bancos ORDER BY Num_banc", connection)

Using drEmployees As OleDb.OleDbDataReader = command.ExecuteReader()

ds.Load( _
drEmployees, _
LoadOption.OverwriteChanges, _
New String() {"Bancos"})
End Using

connection.Close()
End Using

Return ds
Catch err As OleDb.OleDbException

MessageBox.Show(err.Message, "OleDb Exception", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return Nothing
End Try
End Function

Private Sub employeeIDTextBox_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles employeeIDTextBox.Validating
Me.HandleValidation(sender, e, Me.employeeIDTextBox.Text.Trim(), True)
If e.Cancel = True Then
Me.employeeIDTextBox.Focus()
e.Cancel = False
End If
End Sub

Private Sub HandleValidation(ByVal sender As Object, ByVal e As CancelEventArgs, ByVal text As String, ByVal requiresNumeric As Boolean)
Dim err As String = Nothing
Dim numericFailed As Boolean = False
If requiresNumeric Then
Dim output As Integer
Dim isNumeric As Boolean = Integer.TryParse(text, output)
numericFailed = Not isNumeric
End If
If ((text.Length = 0) OrElse numericFailed) Then
err = IIf(requiresNumeric, "Campo numérico requerido", "Campo requerido")
MessageBox.Show("Campo numérico requerido", "Campo requerido", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification, False)
e.Cancel = True
Else
ErrorProvider1.Clear()
End If
End Sub

Private Sub bindingNavigatorExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bindingNavigatorExit.Click
Me.Dispose()
Me.Finalize()
End Sub

Private Sub bindingNavigatorPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bindingNavigatorPrint.Click
Print_Report("Bancos")
End Sub

Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
PrintPreview_Report("Bancos")
End Sub

Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub
End Class
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

RE:¡No me guarda los datos!

Publicado por Damian (824 intervenciones) el 12/11/2010 13:44:44
Te tira algún error o simplemente no te guarda nada?. De todos modos porque no pones algún punto de interrupción para ir viendo los valores de las variables, de los objetos y demás.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar