Documentos de Académico
Documentos de Profesional
Documentos de Cultura
SqlClient
Imports System.Data
Class FRMClientes
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.
Click
If TextBox1.Text.Trim.Length = 0 Then
MessageBox.Show("INGRESE RUC", "MENSAJE", MessageBoxButtons.OK, Mess
ageBoxIcon.Warning)
TextBox1.Focus()
Exit Sub
End If
If TextBox2.Text.Trim.Length = 0 Then
MessageBox.Show("INGRESE NOMBRE", "MENSAJE", MessageBoxButtons.OK, M
essageBoxIcon.Warning)
TextBox2.Focus()
Exit Sub
End If
If TextBox5.Text.Trim.Length = 0 Then
MessageBox.Show("INGRESE CELULAR", "MENSAJE", MessageBoxButtons.OK,
MessageBoxIcon.Warning)
TextBox5.Focus()
Exit Sub
End If
Dim COMANDO As New SqlCommand("INSERT INTO CLIENTE VALUES(@CODCLIENTE,@N
OMBRES,@DIRECCION,@DEPARTAMENTO,@PROVINCIA,@TELEFONO,@CELULAR,@EMAIL)", BDCONEXI
ON.CONEXION)
COMANDO.CommandType = CommandType.Text
COMANDO.Parameters.AddWithValue("@CODCLIENTE", TextBox1.Text)
COMANDO.Parameters.AddWithValue("@NOMBRES", TextBox2.Text)
COMANDO.Parameters.AddWithValue("@DIRECCION", TextBox3.Text)
COMANDO.Parameters.AddWithValue("@DEPARTAMENTO", ComboBox1.SelectedValue
)
COMANDO.Parameters.AddWithValue("@PROVINCIA", ComboBox2.SelectedValue)
COMANDO.Parameters.AddWithValue("@TELEFONO", TextBox4.Text)
COMANDO.Parameters.AddWithValue("@CELULAR", TextBox5.Text)
COMANDO.Parameters.AddWithValue("@EMAIL", TextBox6.Text)
BDCONEXION.CONEXION.Open()
COMANDO.ExecuteNonQuery()
BDCONEXION.CONEXION.Close()
MessageBox.Show("datos grabados", "mensaje", MessageBoxButtons.OK, Messa
geBoxIcon.Warning)
'///////////////CONSULTA CLIENTES//////'
Dim CONSULTACLI As New SqlDataAdapter("SELECT * FROM CLIENTE", BDCONEXIO
N.CONEXION)
CONSULTACLI.SelectCommand.CommandType = CommandType.Text
Dim TABLACLI As New DataTable
CONSULTACLI.Fill(TABLACLI)
DataGridView1.DataSource = TABLACLI
End Sub
Private Sub FRMClientes_Load(sender As Object, e As EventArgs) Handles MyBas
e.Load
Dim CONSULTADEPAR As New _
SqlDataAdapter("SELECT * FROM DEPARTAMENTO",
BDCONEXION.CONEXION)
CONSULTADEPAR.SelectCommand.CommandType = CommandType.Text
Dim TABLA As New DataTable
CONSULTADEPAR.Fill(TABLA)
ComboBox1.DataSource = TABLA
ComboBox1.DisplayMember = "DEPARTAMENTO"
ComboBox1.ValueMember = "CODDEPART"
ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList
Dim CONSULTAPROV As New _
SqlDataAdapter("SELECT * FROM PROVINCIA WHERE CODDEPART=@CODDEPART",
BDCONEXION.CONEXION)
CONSULTAPROV.SelectCommand.CommandType = CommandType.Text
CONSULTAPROV.SelectCommand.Parameters.
AddWithValue("@CODDEPART", ComboBox1.SelectedValue)
Dim TABLAP As New DataTable
CONSULTAPROV.Fill(TABLAP)
ComboBox2.DataSource = TABLAP
ComboBox2.DisplayMember = "PROVINCIA"
ComboBox2.ValueMember = "CODPROV"
ComboBox2.DropDownStyle = ComboBoxStyle.DropDownList
'////////////////////////////////////////////////////////////// CONSULTA
CLIENTES
Dim CONSULTACLI As New _
SqlDataAdapter("SELECT RUC,NOMBRES,DIRECCION,(SELECT DEPARTAMENTO FROM D
EPARTAMENTOS WHERE DEPARTAMENTOS.CODDEPART=CLIENTES.CODDEPART) AS DEPARTAMENTO,(
SELECT PROVINCIA FROM PROVINCIA WHERE PROVINCIA.CODPROV=CLIENTES.CODPROV) AS PRO
VINCIA,TELEFONO,CELULAR,EMAIL FROM CLIENTES",
BDCONEXION.CONEXION)
CONSULTACLI.SelectCommand.CommandType = CommandType.Text
Dim TABLACLI As New DataTable
CONSULTACLI.Fill(TABLACLI)
DataGridView1.DataSource = TABLACLI
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs)
Handles ComboBox1.SelectedIndexChanged
If ComboBox1.SelectedValue.ToString <> "System.Data.DataRowView" Then
Dim CONSULTAPROV As New SqlDataAdapter("SELECT * FROM PROVINCIA WHER
E CODDEPART=@CODDEPART", BDCONEXION.CONEXION)
CONSULTAPROV.SelectCommand.CommandType = CommandType.Text
CONSULTAPROV.SelectCommand.Parameters.AddWithValue("@CODDEPART", Com
boBox1.SelectedValue)
Dim TABLAP As New DataTable
CONSULTAPROV.Fill(TABLAP)
ComboBox2.DataSource = TABLAP
ComboBox2.DisplayMember = "PROVINCIA"
ComboBox2.ValueMember = "CODPROV"
ComboBox2.DropDownStyle = ComboBoxStyle.DropDownList
End If
End Sub
Private Sub TextBox1_Leave(sender As Object, e As EventArgs) Handles TextBox
1.Leave
Dim CONSULTACLI As New SqlDataAdapter("SELECT* FROM CLIENTE WHERE RUC=@R
UC", BDCONEXION.CONEXION)
CONSULTACLI.SelectCommand.CommandType = CommandType.Text
CONSULTACLI.SelectCommand.Parameters.AddWithValue("@RUC", TextBox1.Text)
Dim TABLACLI As New DataTable
CONSULTACLI.Fill(TABLACLI)