Avatar of Supporter
Supporter

asked on 

Search in Database

Now, I have a database which have 2 table : candidates and marks
I want to search the candidate infomation by candidate_code, candidate names, candidate DOB in candidate tables. How can I do it. Help me the code
I created a combobox which search by candidate_code, candidate names, candidate DOB
a textbox to enter value
a button to search
i'm using sqlserver and vb.net 2003
Thanks so much
Visual Basic.NET

Avatar of undefined
Last Comment
Supporter
ASKER CERTIFIED SOLUTION
Avatar of maralans
maralans

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Supporter
Supporter

ASKER

Thanks maralans
But I don't understand

If combobox1= "candidate_code" Then
            dv.RowFilter = " code LIKE '%" + tbSearch.Text + "%' "
        ElseIf combobox1= "candidate names" Then
            dv.RowFilter = " names LIKE '%" + tbSearch.Text + "%' "
        ElseIf combobox1 =  "candidate DOB" Then
            dv.RowFilter = " DOB LIKE '%" + tbSearch.Text + "%' "
               End If
you have 3 variable
code, names, DOB, is it the field in my database

Dim dv As DataView = yourDataSet.Tables(0).DefaultView <~~~ yourDataset <~~~ how I can generat an dataset without using wizard
I often using dataadapter wizard to generat a dataset
here is my code: but I don't know how to generate an dataset

Dim sqlconn As New System.Data.SqlClient.SqlConnection("Data Source=BIP-PCWPUJ7QJPW;Integrated Security=SSPI;Initial Catalog=MCSM;")
        Dim sqlcmd As New System.Data.SqlClient.SqlCommand("SELECT * FROM TblCandidates WHERE Candidate_Code = @Candidate_Code", sqlconn)
        sqlcmd.Parameters.Add("@Candidate_Code", TextBox3.Text)
Avatar of Supporter
Supporter

ASKER

And how to show the searched data in to datagrid
Avatar of maralans
maralans

First you cannot search a dataset directly, you need to create a dataview.  You can either populate your dataset by code or use the wizzard if you find that easier.

 Dim dv As DataView = yourDataSet.Tables(0).DefaultView

Then you need to filter your dataview with your values in the combobox and the textbox.  For example, if your combobox value is DOB and your textbox is 1980 then it would show all records with a DOB of 1980.

If combobox1= "candidate_code" Then
            dv.RowFilter = " code  LIKE '%" + tbSearch.Text + "%' "
        ElseIf combobox1= "candidate names" Then
            dv.RowFilter = " names LIKE '%" + tbSearch.Text + "%' "
        ElseIf combobox1 =  "candidate DOB" Then
            dv.RowFilter = " DOB LIKE '%" + tbSearch.Text + "%' "
End If

And, finally you can sort the dataview.

 If dv.Count < 1 Then
            MessageBox.Show("No records found.", "yourProject", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Else
            dv.Sort = "names "
        End If
   End Sub
Avatar of Supporter
Supporter

ASKER

Yeah. I've done. Thanks so much.
But now, If I choose Candidate DOB to search. I want the search box is datepicker box. Whenever I choose Candidate DOB,  the datepicker box will show and the tbSearch will hide and whenever I choose Candidate Name, the tbSearch will show, and the datepicker will hide. How can I do it

Here is my code, but it doesn't work each time I load my application
        If WinComboBox1.Text = "Candidate Code" Then
            TextBox3.Show()
            WinDatePicker4.Hide()
        End If
        If WinComboBox1.Text = "Candidate Name" Then
            TextBox3.Show()
            WinDatePicker4.Hide()
        End If
        If WinComboBox1.Text = "Candidate DOB" Then
            TextBox3.Hide()
            WinDatePicker4.Show()
        End If
Avatar of maralans
maralans

I don't have VB in front of me but you might could try:

textbox3.visible=false
windatepicker4.visible=true
Avatar of maralans
maralans

Private Sub WinComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles WinComboBox1.SelectedIndexChanged
        If ComboBox1.Text = "Candidate DOB" Then
            DateTimePicker1.Visible = True
            TextBox1.Visible = False
        Else
            DateTimePicker1.Visible = False
            TextBox1.Visible = True
        End If
    End Sub
Avatar of Supporter
Supporter

ASKER

You are Great maralans :)
I've done. I'm now trying to make a report but a made a trouble
the excersise require me create a report that must display the following information
Candidate_Code
Candidate_Name
DOB
Sex
The average mark of each candidate
The average mark of Candidate on each region

another require me create a report that must display the following information
Candidate_Code
Candidate_Name
DOB
Sex
The ratio of Candidates who pass the exam on each region
The ratios of Candidates who pass the exam on all regions

I wonder how to make relationship betwenn tblCandidates and tblMarks in sql server so that I can make report.
Can you help me to build a complete code. I need it to reference
Now I have 2 table in MCSM database
tblCandidates consist of Candidate_Code, Candidate_Name, DOB, Sex, ......
tblMarks consist of Exam_paper_Code, Subject_Code, Candidate_Code, Mark
Avatar of maralans
maralans

You may want to close this question out and then ask a new one if your original question has been answerd.
Avatar of Supporter
Supporter

ASKER

OK, I understand. Thanks you for somuch.
I will post my question again in other topic
Thanks you
Visual Basic.NET
Visual Basic.NET

Visual Basic .NET (VB.NET) is an object-oriented programming language implemented on the .NET framework, but also supported on other platforms such as Mono and Silverlight. Microsoft launched VB.NET as the successor to the Visual Basic language. Though it is similar in syntax to Visual Basic pre-2002, it is not the same technology,

96K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo