Visual basic.net
Estoy trabajando un proyecto con vb.net y mysql ... El problema me surgió cuando utilice en 2 procedimientos unos dataadapter..., el primero lo uso para limpiar ciertos txtbox según los que en la base de datos estén habilitados para ser borrados cada vez que le doy click a dicho botón... Esto lo hace bien la primera vez... Sin problema... Te pongo el código...
Private Sub btnLimpiar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLimpiar.Click
adapt = New MySqlDataAdapter
adapt.MissingSchemaAction = MissingSchemaAction.AddWithKey
Dim sel As New MySqlCommand("select * from conf_bauti", cn)
adapt.SelectCommand = sel
Try
Dim rs2 = New DataSet
rs2.Tables.Clear()
rs2.Clear()
adapt.Fill(rs2)
clvbaut = 0
If rs2.Tables(0).Rows.Count = 0 Then Exit Sub
With rs2.Tables(0)
If .Rows(0)("nom").ToString = 0 Then TextBox1.Text = ""
If .Rows(0)("padre").ToString = 0 Then TextBox2.Text = ""
If .Rows(0)("madre").ToString = 0 Then TextBox3.Text = ""
If .Rows(0)("padrino").ToString = 0 Then TextBox4.Text = ""
If .Rows(0)("madrina").ToString = 0 Then TextBox5.Text = ""
If .Rows(0)("folio").ToString = 0 Then TextBox6.Text = ""
If .Rows(0)("libro").ToString = 0 Then TextBox7.Text = ""
If .Rows(0)("partida").ToString = 0 Then TextBox8.Text = ""
If .Rows(0)("parroco").ToString = 0 Then TextBox9.Text = ""
If .Rows(0)("celebrante").ToString = 0 Then TextBox10.Text = ""
If .Rows(0)("lugnac").ToString = 0 Then TextBox12.Text = ""
If .Rows(0)("fechbaut").ToString = 0 Then DateTimePicker1.Value = Date.Now
If .Rows(0)("fechnac").ToString = 0 Then DateTimePicker2.Value = Date.Now
End With
TextBox11.Text = "---"
TextBox13.Text = "---"
TextBox14.Text = "---"
TextBox15.Text = "---"
DateTimePicker3.Value = Date.Now
btnBorrar.Enabled = False
btnGuardar.Enabled = False
TextBox1.Focus()
rs2.Tables.Clear()
adapt.Dispose()
Catch ex As Exception
MessageBox.Show(ex. Message, "Error (btnLimpiar_Click)", MessageBoxButtons. OK, MessageBoxIcon. Error)
End Try
End Sub
La informacion la obtiene de la tabla conf_bauti... Ok pero a la hora de guardar hay un procedimiento que ejecuto que actualiza cierta informacion empleando un dataset y un dataadapter... Al ejecutar dicho procedimento enseguida vuelvo a llamar el que te puse arriba ...( y ahi es donde truena el programa ... Segun el dataadapter carga el dataset, pero en realidad no tiene nada de informacion... Te estoy hablando del procedimiento de arriba).
te pongo el procedimiento con el que actualizo previo al error....
Private Sub Config_update()
Dim cn2 As New MySqlConnection
'cn2.ConnectionString = "server=localhost;uid=root;database=Notaria;port=3306;pwd=ADMIN"
'cn2.Open()
adapt = New MySqlDataAdapter("select * from conf_bauti", cn)
' adapt.MissingSchemaAction = MissingSchemaAction.AddWithKey
Dim rs1 As DataSet = New DataSet
'Dim matriz(18) As String
Dim keys(0) As DataColumn
Dim com As New MySqlCommandBuilder(adapt)
adapt.Fill(rs1) '--------------------> llena el datatable
'keys(0) = rs.Columns("idconfb")
'rs.PrimaryKey = keys
adapt.UpdateCommand = com.GetUpdateCommand
Try
' clvbaut = 0
With rs1.Tables(0)
If .Rows(0)("nom").ToString = 1 Then .Rows(0)("nom_val") = TextBox1.Text Else .Rows(0)("nom_val") = ""
If .Rows(0)("padre").ToString = 1 Then .Rows(0)("padre_val") = TextBox2.Text Else .Rows(0)("padre_val") = ""
If .Rows(0)("madre").ToString = 1 Then .Rows(0)("madre_val") = TextBox3.Text Else .Rows(0)("madre_val") = ""
If .Rows(0)("padrino").ToString = 1 Then .Rows(0)("padrino_val") = TextBox4.Text Else .Rows(0)("padrino_val") = ""
If .Rows(0)("madrina").ToString = 1 Then .Rows(0)("madrina_val") = TextBox5.Text Else .Rows(0)("madrina_val") = ""
If .Rows(0)("folio").ToString = 1 Then .Rows(0)("folio_val") = TextBox6.Text Else .Rows(0)("folio_val") = ""
If .Rows(0)("libro").ToString = 1 Then .Rows(0)("libro_val") = TextBox7.Text Else .Rows(0)("libro_val") = ""
If .Rows(0)("partida").ToString = 1 Then .Rows(0)("partida_val") = TextBox8.Text Else .Rows(0)("partida_val") = ""
If...
Private Sub btnLimpiar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLimpiar.Click
adapt = New MySqlDataAdapter
adapt.MissingSchemaAction = MissingSchemaAction.AddWithKey
Dim sel As New MySqlCommand("select * from conf_bauti", cn)
adapt.SelectCommand = sel
Try
Dim rs2 = New DataSet
rs2.Tables.Clear()
rs2.Clear()
adapt.Fill(rs2)
clvbaut = 0
If rs2.Tables(0).Rows.Count = 0 Then Exit Sub
With rs2.Tables(0)
If .Rows(0)("nom").ToString = 0 Then TextBox1.Text = ""
If .Rows(0)("padre").ToString = 0 Then TextBox2.Text = ""
If .Rows(0)("madre").ToString = 0 Then TextBox3.Text = ""
If .Rows(0)("padrino").ToString = 0 Then TextBox4.Text = ""
If .Rows(0)("madrina").ToString = 0 Then TextBox5.Text = ""
If .Rows(0)("folio").ToString = 0 Then TextBox6.Text = ""
If .Rows(0)("libro").ToString = 0 Then TextBox7.Text = ""
If .Rows(0)("partida").ToString = 0 Then TextBox8.Text = ""
If .Rows(0)("parroco").ToString = 0 Then TextBox9.Text = ""
If .Rows(0)("celebrante").ToString = 0 Then TextBox10.Text = ""
If .Rows(0)("lugnac").ToString = 0 Then TextBox12.Text = ""
If .Rows(0)("fechbaut").ToString = 0 Then DateTimePicker1.Value = Date.Now
If .Rows(0)("fechnac").ToString = 0 Then DateTimePicker2.Value = Date.Now
End With
TextBox11.Text = "---"
TextBox13.Text = "---"
TextBox14.Text = "---"
TextBox15.Text = "---"
DateTimePicker3.Value = Date.Now
btnBorrar.Enabled = False
btnGuardar.Enabled = False
TextBox1.Focus()
rs2.Tables.Clear()
adapt.Dispose()
Catch ex As Exception
MessageBox.Show(ex. Message, "Error (btnLimpiar_Click)", MessageBoxButtons. OK, MessageBoxIcon. Error)
End Try
End Sub
La informacion la obtiene de la tabla conf_bauti... Ok pero a la hora de guardar hay un procedimiento que ejecuto que actualiza cierta informacion empleando un dataset y un dataadapter... Al ejecutar dicho procedimento enseguida vuelvo a llamar el que te puse arriba ...( y ahi es donde truena el programa ... Segun el dataadapter carga el dataset, pero en realidad no tiene nada de informacion... Te estoy hablando del procedimiento de arriba).
te pongo el procedimiento con el que actualizo previo al error....
Private Sub Config_update()
Dim cn2 As New MySqlConnection
'cn2.ConnectionString = "server=localhost;uid=root;database=Notaria;port=3306;pwd=ADMIN"
'cn2.Open()
adapt = New MySqlDataAdapter("select * from conf_bauti", cn)
' adapt.MissingSchemaAction = MissingSchemaAction.AddWithKey
Dim rs1 As DataSet = New DataSet
'Dim matriz(18) As String
Dim keys(0) As DataColumn
Dim com As New MySqlCommandBuilder(adapt)
adapt.Fill(rs1) '--------------------> llena el datatable
'keys(0) = rs.Columns("idconfb")
'rs.PrimaryKey = keys
adapt.UpdateCommand = com.GetUpdateCommand
Try
' clvbaut = 0
With rs1.Tables(0)
If .Rows(0)("nom").ToString = 1 Then .Rows(0)("nom_val") = TextBox1.Text Else .Rows(0)("nom_val") = ""
If .Rows(0)("padre").ToString = 1 Then .Rows(0)("padre_val") = TextBox2.Text Else .Rows(0)("padre_val") = ""
If .Rows(0)("madre").ToString = 1 Then .Rows(0)("madre_val") = TextBox3.Text Else .Rows(0)("madre_val") = ""
If .Rows(0)("padrino").ToString = 1 Then .Rows(0)("padrino_val") = TextBox4.Text Else .Rows(0)("padrino_val") = ""
If .Rows(0)("madrina").ToString = 1 Then .Rows(0)("madrina_val") = TextBox5.Text Else .Rows(0)("madrina_val") = ""
If .Rows(0)("folio").ToString = 1 Then .Rows(0)("folio_val") = TextBox6.Text Else .Rows(0)("folio_val") = ""
If .Rows(0)("libro").ToString = 1 Then .Rows(0)("libro_val") = TextBox7.Text Else .Rows(0)("libro_val") = ""
If .Rows(0)("partida").ToString = 1 Then .Rows(0)("partida_val") = TextBox8.Text Else .Rows(0)("partida_val") = ""
If...
1 respuesta
Respuesta de Eduardo Saligari