security Posted December 12, 2009 at 07:38 PM Report Share #300067 Posted December 12, 2009 at 07:38 PM Ola. Espero que alguem me possa ajudar a resolver este grave problema com que estou. Tenho um formulário que consiste na pesquisa de Alunos ou Professores, em que a pesquisa e feita por nome, e se encontrar o registo preenche as labels com os respectivos dados, como mostar a imagem Acontece que da-me erro : Dim leitor As OleDb.OleDbDataReader = cmd.ExecuteReader por favor ajudem-me. Preciso de ter isto pronto para Quarta feira... para apresentar para nota. Aqui está o código: Imports System.Data.OleDb Imports System.Windows.Forms.Application Public Class frmPesq Dim cmd As New OleDb.OleDbCommand Dim conn As New OleDbConnection Dim guarda As String Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & Application.StartupPath & "\DBCSG.mdb" If RadioButton1.Checked Then Dim strSQL As String = "select * From alunos where Nome=" & TextBox1.Text Dim cmd As OleDb.OleDbCommand = conn.CreateCommand cmd.CommandText = strSQL conn.Open() Dim leitor As OleDb.OleDbDataReader = cmd.ExecuteReader leitor.Read() Label11.Text = IIf(leitor("cod_int") Is DBNull.Value, "", leitor("cod_int")) Label12.Text = IIf(leitor("Nome") Is DBNull.Value, "", leitor("Nome")) Label13.Text = IIf(leitor("n_BI") Is DBNull.Value, "", leitor("n_BI")) Label14.Text = IIf(leitor("n_fiscal") Is DBNull.Value, "", leitor("n_fiscal")) Label19.Text = IIf(leitor("dataNasc") Is DBNull.Value, "", leitor("dataNasc")) Label20 = IIf(leitor("sexo") Is DBNull.Value, "", leitor("sexo")) Label21.Text = IIf(leitor("cp1") Is DBNull.Value, "", leitor("cp1")) Label22.Text = IIf(leitor("cp2") Is DBNull.Value, "", leitor("cp2")) Label23.Text = IIf(leitor("morada") Is DBNull.Value, "", leitor("morada")) Label24.Text = IIf(leitor("freguesia") Is DBNull.Value, "", leitor("freguesia")) Label25.Text = IIf(leitor("concelho") Is DBNull.Value, "", leitor("concelho")) Label26.Text = IIf(leitor("distrito") Is DBNull.Value, "", leitor("distrito")) Label27.Text = IIf(leitor("nacionalidade") Is DBNull.Value, "", leitor("nacionalidade")) ElseIf RadioButton2.Checked Then conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & Application.StartupPath & "\DBCSG.mdb" guarda = TextBox1.Text Dim strSQL As String = "select * From profs where Nome=" & guarda Dim cmd As OleDb.OleDbCommand = conn.CreateCommand cmd.CommandText = strSQL conn.Open() Dim leitor As OleDb.OleDbDataReader = cmd.ExecuteReader() MsgBox(guarda) leitor.Read() Label11.Text = IIf(leitor("cod_int") Is DBNull.Value, "", leitor("cod_int")) Label12.Text = IIf(leitor("Nome") Is DBNull.Value, "", leitor("Nome")) Label13.Text = IIf(leitor("n_BI") Is DBNull.Value, "", leitor("n_BI")) Label14.Text = IIf(leitor("n_fiscal") Is DBNull.Value, "", leitor("n_fiscal")) Label19.Text = IIf(leitor("dataNasc") Is DBNull.Value, "", leitor("dataNasc")) Label20 = IIf(leitor("sexo") Is DBNull.Value, "", leitor("sexo")) Label21.Text = IIf(leitor("cp1") Is DBNull.Value, "", leitor("cp1")) Label22.Text = IIf(leitor("cp2") Is DBNull.Value, "", leitor("cp2")) Label23.Text = IIf(leitor("morada") Is DBNull.Value, "", leitor("morada")) Label24.Text = IIf(leitor("freguesia") Is DBNull.Value, "", leitor("freguesia")) Label25.Text = IIf(leitor("concelho") Is DBNull.Value, "", leitor("concelho")) Label26.Text = IIf(leitor("distrito") Is DBNull.Value, "", leitor("distrito")) Label27.Text = IIf(leitor("nacionalidade") Is DBNull.Value, "", leitor("nacionalidade")) conn.Close() Else MsgBox("Não foi encontrado o registo. Deseja Cria-lo?", MsgBoxStyle.Exclamation, MsgBoxStyle.YesNoCancel) End If End Sub End Class Obrigado "Innovation distinguishes between a leader and a follower." Steve jobs. Link to comment Share on other sites More sharing options...
vbtipo Posted December 13, 2009 at 08:03 PM Report Share #300196 Posted December 13, 2009 at 08:03 PM Dá-te o erro tens que nos dizer realmente o que diz o erro? Senão é-nos difícil ou mesmo impossível de ajudar. Ps: Pelo código isto é vb.net e não vb6. Lema: Se eu não saber de alguma coisa não se preocupem porque tento sempre ajudar alguma coisita, nem que seja, por palpites/sugestões. Link to comment Share on other sites More sharing options...
security Posted December 13, 2009 at 10:16 PM Author Report Share #300213 Posted December 13, 2009 at 10:16 PM o erro que da é: Erro de sintaxe (operador em falta) na expressão de consulta 'Nome=Rui Manuel Casimiro De Santos Sousa''. O nome Rui Manuel Casimiro De Santos Sousa é o nome pela qual a pesquisa deve ser feita. O erro da-me na linha que referi no postagem inicial "Innovation distinguishes between a leader and a follower." Steve jobs. Link to comment Share on other sites More sharing options...
renafi Posted December 13, 2009 at 11:42 PM Report Share #300229 Posted December 13, 2009 at 11:42 PM uma hipótese é teres de enviar o nome em ' ' Tipo: Dim strSQL As String = "select * From alunos where Nome='" & TextBox1.Text & "'" Atenção: não se vê bem, mas tem ' ' junto com as aspas Experimenta Oracle Certified Professional - AdministraçãoOracle Certified Professional - Pl/sqlMCPD - Microsoft Certified Professional DeveloperMCTS - Microsoft Certified Technology Specialist Link to comment Share on other sites More sharing options...
security Posted December 14, 2009 at 09:24 PM Author Report Share #300401 Posted December 14, 2009 at 09:24 PM obrigado... o problema foi resolvido mas surgiu-me um outro erro que apenas diz "cod_int" (é o nome de um campo da minha base de dados), onde deveria listar os valores nas labels, ou seja no codigo seguinte: Label11.Text = IIf(leitor("cod_int") Is DBNull.Value, "", leitor("cod_int")) Label12.Text = IIf(leitor("Nome") Is DBNull.Value, "", leitor("Nome")) Label13.Text = IIf(leitor("n_BI") Is DBNull.Value, "", leitor("n_BI")) Label14.Text = IIf(leitor("n_fiscal") Is DBNull.Value, "", leitor("n_fiscal")) Label19.Text = IIf(leitor("dataNasc") Is DBNull.Value, "", leitor("dataNasc")) Label20 = IIf(leitor("sexo") Is DBNull.Value, "", leitor("sexo")) Label21.Text = IIf(leitor("cp1") Is DBNull.Value, "", leitor("cp1")) Label22.Text = IIf(leitor("cp2") Is DBNull.Value, "", leitor("cp2")) Label23.Text = IIf(leitor("morada") Is DBNull.Value, "", leitor("morada")) Label24.Text = IIf(leitor("freguesia") Is DBNull.Value, "", leitor("freguesia")) Label25.Text = IIf(leitor("concelho") Is DBNull.Value, "", leitor("concelho")) Label26.Text = IIf(leitor("distrito") Is DBNull.Value, "", leitor("distrito")) Label27.Text = IIf(leitor("nacionalidade") Is DBNull.Value, "", leitor("nacionalidade")) "Innovation distinguishes between a leader and a follower." Steve jobs. 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