elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: (TUTORIAL) Aprende a emular Sentinel Dongle By Yapis


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  Problema con base de datos y VB.net
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Problema con base de datos y VB.net  (Leído 3,125 veces)
oscarj24

Desconectado Desconectado

Mensajes: 65


Ver Perfil
Problema con base de datos y VB.net
« en: 21 Junio 2010, 01:52 am »

Hola a todos, soy nuevo en VB.Net y estoy haciendo una aplicacion que me permite ver la informacion obtenida mediante un formulario en PHP. Todo esto utilizando el Driver ODBC.
 ;-)
Hasta ahi todo bien

El formulario es el siguiente:


El Tabla SQL es la siguiente:

(utilizo todo VARCHAR ya que en la aplicacion solo muestro datos,
no efectuo operaciones con los valores, por lo tanto no es necesario
reconocer un valor INT :))

Y mi aplicacion, la siguiente:


Ahora, mis problemas son los siguientes:

1) Quiero hacer que el comboBox con los ID's carguen en la posicion 1
o sea que la posicion 0 sea "Seleccione".. ejemplo:

cboID.Items.Add("Seleccione") -> Posicion cero
cboID.Items.Add("ID01") -> Posicion uno
Y Asi todos los ID's de la DB, es eso posible?

2) Tengo un problema al actualizar los datos. Al dar click en "Editar"
y luego "Grabar" y ejecutar la consulta UPDATE en la DB.
SIEMPRE, asi el textbox este vacio o lleno, SIEMPRE me agrega un
NULL a la base de datos y nose como arreglar eso. Luego, cuando
intento ver los valores modificados, el programa se cae ya que
dice que un tipo DBNull no puede ser convertido a tipo String (Este
problema tampoco lo se controlar)

Espero me puedan ayudar a controlar los NULL's
A ver porque siempre se envian los datos como NULL
y a poder arreglar el comboBox como deseo

Aqui les paso el codigo del Boton Grabar:
Código
  1. Private Sub Grabar(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGrabar.Click
  2.        Dim obj As New frmLogin()
  3.        If operacion = TipoOperacion.Ninguna Then
  4.            MessageBox.Show("No hay nada que 'Grabar'.", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  5.        Else
  6.            If txtNombres.Text.Trim.Length > 0 Then
  7.                If txtApellidos.Text.Trim.Length > 0 Then
  8.                    If txtDNICarneExtranjeria.Text.Trim.Length > 0 Then
  9.                        If txtTelefonoFijo.Text.Trim.Length > 0 Or txtCelular.Text.Trim.Length > 0 Then
  10.                            obj.con.Open()
  11.                            Dim cmd As New OdbcCommand("", obj.con)
  12.                            Dim mensaje As String = ""
  13.                            If MessageBox.Show("Seguro de Guardar la Inscripción?", "Aviso", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
  14.                                If operacion = TipoOperacion.Actualizar Then
  15.                                    cmd.CommandText = "UPDATE inscripciones SET Nombres=@Nombres,Apellidos=@Apellidos,DNI_CarneExtranjeria=@DNI_CarneExtranjeria,Tipo_Persona=@Tìpo_Persona,Empresa=@Empresa,Cargo=@Cargo,Direccion=@Direccion,Telefono_Fijo=@Telefono_Fijo,Telefono_Celular=@Telefono_Celular,Tipo_Comprobante=@Tipo_Comprobante,Razon_Social=@Razon_Social,RUC=@RUC,Nombre_Voucher=@Nombre_Voucher WHERE ID=" & cboID.SelectedValue
  16.                                    mensaje = "Inscripción Actualizada."
  17.                                End If
  18.                                cmd.Parameters.Add("@Nombres", OdbcType.VarChar, 50).Value = txtNombres.Text
  19.                                cmd.Parameters.Add("@Apellidos", OdbcType.VarChar, 50).Value = txtApellidos.Text
  20.                                cmd.Parameters.Add("@DNI_CarneExtranjeria", OdbcType.VarChar, 15).Value = txtDNICarneExtranjeria.Text
  21.                                cmd.Parameters.Add("@Tipo_Persona", OdbcType.VarChar, 13).Value = txtTipoPersona.Text
  22.                                cmd.Parameters.Add("@Empresa", OdbcType.VarChar, 60).Value = txtEmpresa.Text
  23.                                cmd.Parameters.Add("@Cargo", OdbcType.VarChar, 30).Value = txtCargo.Text
  24.                                cmd.Parameters.Add("@Direccion", OdbcType.VarChar, 100).Value = txtDireccion.Text
  25.                                cmd.Parameters.Add("@Telefono_Fijo", OdbcType.VarChar, 25).Value = txtTelefonoFijo.Text
  26.                                cmd.Parameters.Add("@Telefono_Celular", OdbcType.VarChar, 25).Value = txtCelular.Text
  27.                                cmd.Parameters.Add("@Tipo_Comprobante", OdbcType.VarChar, 7).Value = txtTipoComprobante.Text
  28.                                cmd.Parameters.Add("@Razon_Social", OdbcType.VarChar, 60).Value = txtRazonSocial.Text
  29.                                cmd.Parameters.Add("@RUC", OdbcType.VarChar, 11).Value = txtRUC.Text
  30.                                cmd.Parameters.Add("@Nombre_Voucher", OdbcType.VarChar, 50).Value = txtNombreVoucher.Text
  31.                                Dim N As Integer = cmd.ExecuteNonQuery
  32.                                If N > 0 Then
  33.                                    MessageBox.Show(mensaje, "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Information)
  34.                                    btnEliminar.Enabled = True
  35.                                    btnGrabar.Enabled = False
  36.                                    ConsultarInscrito()
  37.                                    cboID.Focus()
  38.                                Else
  39.                                    MessageBox.Show("No se pudo Realizar la Operación.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
  40.                                    btnEliminar.Enabled = True
  41.                                    btnGrabar.Enabled = False
  42.                                    cboID.Focus()
  43.                                End If
  44.                                obj.con.Close()
  45.                                operacion = TipoOperacion.Ninguna
  46.                                HabilitarControles(False)
  47.                                cboID.Enabled = True
  48.                                btnCancelar.Enabled = False
  49.                                cboID.Focus()
  50.                            Else
  51.                                txtNombres.Focus()
  52.                            End If
  53.                        Else
  54.                            MessageBox.Show("Ingrese al menos un 'Teléfono'.", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  55.                            txtTelefonoFijo.Focus()
  56.                        End If 'Telefonos
  57.                        Else
  58.                            MessageBox.Show("Ingrese el 'DNI o Carne de Extranjería'.", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  59.                            txtDNICarneExtranjeria.Focus()
  60.                        End If 'DNI o Carne Extranjeria
  61.                    Else
  62.                        MessageBox.Show("Ingrese los 'Apellidos'.", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  63.                        txtApellidos.Focus()
  64.                    End If 'Apellidos
  65.                Else
  66.                    MessageBox.Show("Ingrese los 'Nombres'.", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  67.                    txtNombres.Focus()
  68.                End If 'Nombres
  69.        End If
  70.    End Sub


Y el codigo del metodo Consultar Inscrito que se usa el boton Grabar para hacer una especie de "Refresh" cuando los datos se grabaron:
Código
  1. Private Sub ConsultarInscrito()
  2.        Dim obj As New frmLogin()
  3.        obj.con.Open()
  4.        Dim cmd As New OdbcCommand("SELECT Nombres,Apellidos,DNI_CarneExtranjeria,Tipo_Persona,Empresa,Cargo,Direccion,Telefono_Fijo,Telefono_Celular,Tipo_Comprobante,Razon_Social,RUC,Nombre_Voucher FROM inscripciones WHERE ID=" & cboID.SelectedValue, obj.con)
  5.        Dim drd As OdbcDataReader = cmd.ExecuteReader(CommandBehavior.SingleRow)
  6.        If drd.HasRows = False Then
  7.            MessageBox.Show("No hay 'Datos' por mostrar'.", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  8.        End If
  9.        If drd IsNot Nothing Then
  10.            If drd.HasRows Then
  11.                drd.Read()
  12.                txtNombres.Text = drd.GetString(0)
  13.                txtApellidos.Text = drd.GetString(1)
  14.                txtDNICarneExtranjeria.Text = drd.GetString(2)
  15.                txtTipoPersona.Text = drd.GetString(3)
  16.                txtEmpresa.Text = drd.GetString(4)
  17.                txtCargo.Text = drd.GetString(5)
  18.                txtDireccion.Text = drd.GetString(6)
  19.                txtTelefonoFijo.Text = drd.GetString(7)
  20.                txtCelular.Text = drd.GetString(8)
  21.                txtTipoComprobante.Text = drd.GetString(9)
  22.                txtRazonSocial.Text = drd.GetString(10)
  23.                txtRUC.Text = drd.GetString(11)
  24.                txtNombreVoucher.Text = drd.GetString(12)
  25.                wbVoucher.Navigate("http://www.dominio.com/inscripciones/vouchers/" + txtNombreVoucher.Text)
  26.                cboID.Focus()
  27.                btnEditar.Enabled = True
  28.                btnEliminar.Enabled = True
  29.                drd.Close()
  30.            End If
  31.        End If
  32.        obj.con.Close()
  33.        cboID.Enabled = True
  34.        btnEliminar.Enabled = True
  35.    End Sub
  36.  

GRACIAS y en verdad espero su ayuda  ;D


En línea

oscarj24

Desconectado Desconectado

Mensajes: 65


Ver Perfil
Re: Problema con base de datos y VB.net
« Respuesta #1 en: 21 Junio 2010, 02:09 am »

PD. Olvide decir que tambien me gustaria poder guardar un NULL como un espacio en blanco " " si es que se diera la oportunidad de necesitarlo (nose si sea posible) gracias.


En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Problema con ID en base de datos
PHP
Feedeex 1 1,741 Último mensaje 22 Diciembre 2010, 17:03 pm
por Devilboy.Devil
Problema ID base de datos
Bases de Datos
Riki_89D 2 2,523 Último mensaje 27 Diciembre 2010, 23:56 pm
por cassiani
problema con base de datos
Bases de Datos
Basil 3 2,767 Último mensaje 3 Enero 2011, 09:02 am
por Basil
Problema con base de datos y Eclipse
Java
carlesq 0 1,955 Último mensaje 15 Noviembre 2012, 16:58 pm
por carlesq
problema con diseño de una base de datos
Bases de Datos
abbyblack123 4 3,463 Último mensaje 11 Marzo 2013, 00:39 am
por Carloswaldo
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines