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:
Private Sub Grabar(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGrabar.Click
Dim obj As New frmLogin()
If operacion = TipoOperacion.Ninguna Then
MessageBox.Show("No hay nada que 'Grabar'.", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Else
If txtNombres.Text.Trim.Length > 0 Then
If txtApellidos.Text.Trim.Length > 0 Then
If txtDNICarneExtranjeria.Text.Trim.Length > 0 Then
If txtTelefonoFijo.Text.Trim.Length > 0 Or txtCelular.Text.Trim.Length > 0 Then
obj.con.Open()
Dim cmd As New OdbcCommand("", obj.con)
Dim mensaje As String = ""
If MessageBox.Show("Seguro de Guardar la Inscripción?", "Aviso", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
If operacion = TipoOperacion.Actualizar Then
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
mensaje = "Inscripción Actualizada."
End If
cmd.Parameters.Add("@Nombres", OdbcType.VarChar, 50).Value = txtNombres.Text
cmd.Parameters.Add("@Apellidos", OdbcType.VarChar, 50).Value = txtApellidos.Text
cmd.Parameters.Add("@DNI_CarneExtranjeria", OdbcType.VarChar, 15).Value = txtDNICarneExtranjeria.Text
cmd.Parameters.Add("@Tipo_Persona", OdbcType.VarChar, 13).Value = txtTipoPersona.Text
cmd.Parameters.Add("@Empresa", OdbcType.VarChar, 60).Value = txtEmpresa.Text
cmd.Parameters.Add("@Cargo", OdbcType.VarChar, 30).Value = txtCargo.Text
cmd.Parameters.Add("@Direccion", OdbcType.VarChar, 100).Value = txtDireccion.Text
cmd.Parameters.Add("@Telefono_Fijo", OdbcType.VarChar, 25).Value = txtTelefonoFijo.Text
cmd.Parameters.Add("@Telefono_Celular", OdbcType.VarChar, 25).Value = txtCelular.Text
cmd.Parameters.Add("@Tipo_Comprobante", OdbcType.VarChar, 7).Value = txtTipoComprobante.Text
cmd.Parameters.Add("@Razon_Social", OdbcType.VarChar, 60).Value = txtRazonSocial.Text
cmd.Parameters.Add("@RUC", OdbcType.VarChar, 11).Value = txtRUC.Text
cmd.Parameters.Add("@Nombre_Voucher", OdbcType.VarChar, 50).Value = txtNombreVoucher.Text
Dim N As Integer = cmd.ExecuteNonQuery
If N > 0 Then
MessageBox.Show(mensaje, "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Information)
btnEliminar.Enabled = True
btnGrabar.Enabled = False
ConsultarInscrito()
cboID.Focus()
Else
MessageBox.Show("No se pudo Realizar la Operación.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
btnEliminar.Enabled = True
btnGrabar.Enabled = False
cboID.Focus()
End If
obj.con.Close()
operacion = TipoOperacion.Ninguna
HabilitarControles(False)
cboID.Enabled = True
btnCancelar.Enabled = False
cboID.Focus()
Else
txtNombres.Focus()
End If
Else
MessageBox.Show("Ingrese al menos un 'Teléfono'.", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
txtTelefonoFijo.Focus()
End If 'Telefonos
Else
MessageBox.Show("Ingrese el 'DNI o Carne de Extranjería'.", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
txtDNICarneExtranjeria.Focus()
End If 'DNI o Carne Extranjeria
Else
MessageBox.Show("Ingrese los 'Apellidos'.", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
txtApellidos.Focus()
End If 'Apellidos
Else
MessageBox.Show("Ingrese los 'Nombres'.", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
txtNombres.Focus()
End If 'Nombres
End If
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:
Private Sub ConsultarInscrito()
Dim obj As New frmLogin()
obj.con.Open()
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)
Dim drd As OdbcDataReader = cmd.ExecuteReader(CommandBehavior.SingleRow)
If drd.HasRows = False Then
MessageBox.Show("No hay 'Datos' por mostrar'.", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
If drd IsNot Nothing Then
If drd.HasRows Then
drd.Read()
txtNombres.Text = drd.GetString(0)
txtApellidos.Text = drd.GetString(1)
txtDNICarneExtranjeria.Text = drd.GetString(2)
txtTipoPersona.Text = drd.GetString(3)
txtEmpresa.Text = drd.GetString(4)
txtCargo.Text = drd.GetString(5)
txtDireccion.Text = drd.GetString(6)
txtTelefonoFijo.Text = drd.GetString(7)
txtCelular.Text = drd.GetString(8)
txtTipoComprobante.Text = drd.GetString(9)
txtRazonSocial.Text = drd.GetString(10)
txtRUC.Text = drd.GetString(11)
txtNombreVoucher.Text = drd.GetString(12)
wbVoucher.Navigate("http://www.dominio.com/inscripciones/vouchers/" + txtNombreVoucher.Text)
cboID.Focus()
btnEditar.Enabled = True
btnEliminar.Enabled = True
drd.Close()
End If
End If
obj.con.Close()
cboID.Enabled = True
btnEliminar.Enabled = True
End Sub
GRACIAS y en verdad espero su ayuda
