Private Sub TextBox1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Leave
TextBox1.BackColor = Color.White
cgccpf = TextBox1.Text
Dim Numdig As Integer = TextBox1.TextLength
If Numdig > 0 Then
If Numdig < 11 Or Numdig > 14 Then
MessageBox.Show("Numero de digitos invalido para CPF e CNPJ")
TextBox1.Text = TextBox1.Text
TextBox1.Focus()
End If
If Numdig > 11 And Numdig <= 13 Then
MessageBox.Show("Numero de digitos invalido para CPF e CNPJ")
TextBox1.Text = TextBox1.Text
TextBox1.Focus()
End If
If Numdig = 11 Then
If ValidarCPF(TextBox1.Text.Trim) = False Then
MessageBox.Show("O CPF informado não é valido ... ")
TextBox1.Text = TextBox1.Text
TextBox1.Focus()
Else
'MessageBox.Show("O CPF esta OK ... ")
TextBox1.Text = Mid(TextBox1.Text, 1, 3) & "." & Mid(TextBox1.Text, 4, 3) & "." & Mid(TextBox1.Text, 7, 3) & "-" & Mid(TextBox1.Text, 10, 2)
End If
End If
If Numdig = 14 Then
If ValidarCNPJ(TextBox1.Text.Trim) = False Then
MessageBox.Show("O CNPJ informado não é valido ... ")
TextBox1.Text = TextBox1.Text
TextBox1.Focus()
Else
'MessageBox.Show("O CNPJ esta OK ... ")
TextBox1.Text = Mid(TextBox1.Text, 1, 2) & "." & Mid(TextBox1.Text, 3, 3) & "." & Mid(TextBox1.Text, 6, 3) & "/" & Mid(TextBox1.Text, 9, 4) & "-" & Mid(TextBox1.Text, 13, 2)
End If
End If
End If
Dim conn As New SqlClient.SqlConnection
Dim comando As New SqlClient.SqlCommand
Dim dr_cli As SqlClient.SqlDataReader
conn.ConnectionString = My.Settings.SisvenConnectionString
Try
conn.Open()
comando.Connection = conn
'Vê se o cliente já esta cadastrado ou não
comando.Parameters.AddWithValue("@cgccpf", cgccpf)
comando.CommandText = "Select cgccpf FROM cadcli Where cgccpf=@cgccpf"
dr_cli = comando.ExecuteReader()
' Carregar os TEXTBOX do formulario com as informacoes da tabela
If dr_cli.Read() Then
While dr_cli.Read()
TextBox1.Text = dr_cli.Item(0)
TextBox2.Text = dr_cli.Item(1)
'continua ate carregar todas as informacoes da tabela
End While
Else
Console.WriteLine("Registro não encontrado.")
End If
'Fecha o sqlDataReader e o SqlConnection
conn.Close()
Catch ex As Exception
MessageBox.Show("Erro ao efetuar a conexão com a base de dados :" + ex.Message)
Finally
conn.Close()
conn.Dispose()
End Try
End Sub
**** O Q TÁ ERRADO, QUERO ALGO SIMPLES ... LER NA TABELA E CARREGAR NOS TEXTBOX ***
Pergunta
Guest Rubens Paulino
Private Sub TextBox1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Leave TextBox1.BackColor = Color.White cgccpf = TextBox1.Text Dim Numdig As Integer = TextBox1.TextLength If Numdig > 0 Then If Numdig < 11 Or Numdig > 14 Then MessageBox.Show("Numero de digitos invalido para CPF e CNPJ") TextBox1.Text = TextBox1.Text TextBox1.Focus() End If If Numdig > 11 And Numdig <= 13 Then MessageBox.Show("Numero de digitos invalido para CPF e CNPJ") TextBox1.Text = TextBox1.Text TextBox1.Focus() End If If Numdig = 11 Then If ValidarCPF(TextBox1.Text.Trim) = False Then MessageBox.Show("O CPF informado não é valido ... ") TextBox1.Text = TextBox1.Text TextBox1.Focus() Else 'MessageBox.Show("O CPF esta OK ... ") TextBox1.Text = Mid(TextBox1.Text, 1, 3) & "." & Mid(TextBox1.Text, 4, 3) & "." & Mid(TextBox1.Text, 7, 3) & "-" & Mid(TextBox1.Text, 10, 2) End If End If If Numdig = 14 Then If ValidarCNPJ(TextBox1.Text.Trim) = False Then MessageBox.Show("O CNPJ informado não é valido ... ") TextBox1.Text = TextBox1.Text TextBox1.Focus() Else 'MessageBox.Show("O CNPJ esta OK ... ") TextBox1.Text = Mid(TextBox1.Text, 1, 2) & "." & Mid(TextBox1.Text, 3, 3) & "." & Mid(TextBox1.Text, 6, 3) & "/" & Mid(TextBox1.Text, 9, 4) & "-" & Mid(TextBox1.Text, 13, 2) End If End If End If Dim conn As New SqlClient.SqlConnection Dim comando As New SqlClient.SqlCommand Dim dr_cli As SqlClient.SqlDataReader conn.ConnectionString = My.Settings.SisvenConnectionString Try conn.Open() comando.Connection = conn 'Vê se o cliente já esta cadastrado ou não comando.Parameters.AddWithValue("@cgccpf", cgccpf) comando.CommandText = "Select cgccpf FROM cadcli Where cgccpf=@cgccpf" dr_cli = comando.ExecuteReader() ' Carregar os TEXTBOX do formulario com as informacoes da tabela If dr_cli.Read() Then While dr_cli.Read() TextBox1.Text = dr_cli.Item(0) TextBox2.Text = dr_cli.Item(1) 'continua ate carregar todas as informacoes da tabela End While Else Console.WriteLine("Registro não encontrado.") End If 'Fecha o sqlDataReader e o SqlConnection conn.Close() Catch ex As Exception MessageBox.Show("Erro ao efetuar a conexão com a base de dados :" + ex.Message) Finally conn.Close() conn.Dispose() End Try End Sub**** O Q TÁ ERRADO, QUERO ALGO SIMPLES ... LER NA TABELA E CARREGAR NOS TEXTBOX ***
Link para o comentário
Compartilhar em outros sites
4 respostass a esta questão
Posts Recomendados
Participe da discussão
Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.