Chemykal Posted October 20, 2011 Report Share Posted October 20, 2011 Las Regiones con las provincias no filtran correctamente alguien podria ayudarme? Public Class addcomunass Public con As New classconexion Public Sub llenar_regiones() Dim Sql1 As String = "SELECT * FROM regiones" Dim EJECUTAR As New MySQLDriverCS.MySQLCommand(Sql1, con.con) 'con.conectar() EJECUTAR.ExecuteScalar() Dim da As New MySQLDriverCS.MySQLDataAdapter(EJECUTAR) Dim tabla As New DataSet da.Fill(tabla) ComboBox1.DataSource = tabla.Tables(0) ComboBox1.DisplayMember = "reg_nom" End Sub Private Sub addcomunas_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load con.conectar() llenar_regiones() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim sql As String = "INSERT INTO comunas(com_nom,com_cod,)" sql += "VALUES('" & TextBox1.Text & "','" & TextBox2.Text & "')" Dim cmd As New MySQLDriverCS.MySQLCommand(sql, con.con) cmd.ExecuteReader() MsgBox("Los datos de t han sido guardados", MsgBoxStyle.Information, "") Me.Hide() End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Me.Close() End Sub Private Sub cmb1_SelectionChangeCommitted(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectionChangeCommitted 'Try Dim val As Integer Dim Sql1 As String = "SELECT reg_cod FROM regiones where reg_nom='" & ComboBox1.SelectedText & "'" Dim EJECUTAR As New MySQLDriverCS.MySQLCommand(Sql1, con.con) 'con.conectar() EJECUTAR.ExecuteScalar() Dim da As New MySQLDriverCS.MySQLDataAdapter(EJECUTAR) Dim tabla As New DataTable da.Fill(tabla) For Each dt As DataRow In tabla.Rows val = dt(0) Next Dim Sql As String = "SELECT * FROM PROVINCIAS where prov_reg_cod='" & val & "'" Dim EJECUTAR1 As New MySQLDriverCS.MySQLCommand(Sql, con.con) 'con.conectar() EJECUTAR1.ExecuteScalar() Dim da1 As New MySQLDriverCS.MySQLDataAdapter(EJECUTAR1) Dim tabla1 As New DataSet da1.Fill(tabla1) ComboBox2.DataSource = tabla1.Tables(0) ComboBox2.DisplayMember = "prov_nom" 'Catch 'End Try End SubEnd Class Link to comment Share on other sites More sharing options...
eduardoherre Posted October 27, 2011 Report Share Posted October 27, 2011 (edited) Estimado que tal, intenta esto Public Sub llenar_regiones()Dim Sql1 As String = "SELECT * FROM regiones"Dim EJECUTAR As New MySQLDriverCS.MySQLCommand(Sql1, con.con)'con.conectar()EJECUTAR.ExecuteScalar()Dim da As New MySQLDriverCS.MySQLDataAdapter(EJECUTAR)Dim tabla As New DataSetda.Fill(tabla)ComboBox1.DataSource = tabla.Tables(0)ComboBox1.DisplayMember = "reg_nom"ComboBox.ValueMember="id_region"End Sub al llamar y comparar pk no llamas a su fk por eso no hace nada, pero si instancias a su pk y fk tienen la relación ej: id_region(pk) nom_region1 V Región2 IV Region id_provincia(pk) id_region(fk) nombre_provincia1 1 Valparaiso2 1 Viña del mar3 2 La serena para llenar tu instancia en relación con tus dos tablas regiones/ provincias, la consulta sql debe ser (select * from provincia where id_region(fk) = " & cmb_region.SelectedValue& "") luego asignas la consulta y llenas tu combobox DisplayMember= "nombre columna provincia"ValueMember="id_provincia" en el manejo de exepciones trata de controlarlo con mensajes para saber donde esta la exepcion y no pasarla por alto no mas una sugerencia trata de introducirte un poco mas en procedimientos almacenados para sql, y cuando instancies a tus clases hazlo de forma ordenada, piensa que el código se va ejecutando hacia abajo, funciona igual pero te recomendaria eso. saludos Edited October 27, 2011 by eduardoherre Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now