sir will you please help me and send me query for this...

Recommended Answers

All 3 Replies

@waqasmrd:
I like to tell that make your question on distinct problem, what you are facing to get your desred result. Post your codes, how far you did and what result you have got and what you have desired to get.

There are too many process to make a query and it depands on which type of file you are using to store your data.

con.Open()

                    Dim dr As SqlDataReader
                    Dim stdr As String
                    Dim stdn As String
                    cmd = New SqlCommand("select * from student where stdRegno like '" & srcstudent.Text & "'", con)
                    dr = cmd.ExecuteReader
                    If dr.Read = True Then
                        stdr = dr(0)
                        stdn = dr(1)
                        dr.Close()
                        Dim value As String
                        Dim pass As String
                        value = Me.srcstudent.Text
                        pass = StrConv(value, VbStrConv.ProperCase)
                        If pass = stdr Then
                            Dim sdf As String = "select Stdname,Fname,Rollno,Dept,Session from student where stdRegno  like '" & pass & "'"
                            cmd = New SqlCommand(sdf, con)
                            Dim da As New SqlDataAdapter(cmd)
                            Dim ds As New DataSet
                            ds.Clear()
                            da.Fill(ds)
                            DataGridView1.DataSource = ds.Tables(0)
                            DataGridView1.Show()
                            imageshow()
                        End If
                    Else
                        'RNF1.Show()
                        'ERN1.Hide()
                        cmd = New SqlCommand("select * from student where Stdname like '" & srcstudent.Text & "'", con)
                        dr = cmd.ExecuteReader
                        If dr.Read = True Then
                            dr.Close()
                            Dim value1 As String
                            Dim pass1 As String
                            value1 = Me.srcstudent.Text
                            pass1 = StrConv(value1, VbStrConv.ProperCase)
                            If pass1 Then
                            Dim sdf As String = "select Stdname,Fname,Rollno,Dept,Session from student where stdRegno  like '" &  & "'"
                                cmd = New SqlCommand(sdf, con)
                                Dim da As New SqlDataAdapter(cmd)
                                Dim ds As New DataSet
                                ds.Clear()
                                da.Fill(ds)
                                DataGridView1.DataSource = ds.Tables(0)
                                DataGridView1.Show()
                                imageshow()
                            End If

                        End If
                        End If

                        con.Close()
                End If

sir this is my code and i want query that perform both actions from one textbox ...but i dont have idea that how to do this .... sir is this possible to give to conditions in one query like...
select * from student where stdregno like '"&srctext.text&"' or "stdname like '"&srctext.text&"'"

It could be done by an one SQL Statement. But student regdno should be unique. Creating query by regdno you can get only one result for that particular regdno. The codes should be

 con.Open()
            Dim dr As SqlDataReader
            Dim stdr As String
            Dim stdn As String
            Dim cmd As SqlClient.SqlCommand = New SqlCommand("select stdRegno,Stdname,Fname,Rollno,Dept,Session from student where stdRegno ='" & srcstudent.Text & "'", con)

            Dim da As New SqlDataAdapter(cmd)
            Dim ds As New DataSet
            ds.Clear()
            da.Fill(ds)
            DataGridView1.DataSource = ds.Tables(0)
            DataGridView1.Show()
            imageshow()

            con.Close()

If you like to get all students whose names are same the codes should be

 con.Open()
            Dim dr As SqlDataReader
            Dim stdr As String
            Dim stdn As String
            Dim cmd As SqlClient.SqlCommand = New SqlCommand("select stdRegno,Stdname,Fname,Rollno,Dept,Session from student where Stdname ='" & StrConv(srcstudent.Text, VbStrConv.ProperCase) & "'", con)

            Dim da As New SqlDataAdapter(cmd)
            Dim ds As New DataSet
            ds.Clear()
            da.Fill(ds)
            DataGridView1.DataSource = ds.Tables(0)
            DataGridView1.Show()
            imageshow()

            con.Close()

But as per your requirment the codes should be the following. It will be gave you the result whose regdno is eual to the supplied text and with it all the students whose names are same as the text.

con.Open()
        Dim dr As SqlDataReader
        Dim stdr As String
        Dim stdn As String
        Dim cmd As SqlClient.SqlCommand = New SqlCommand("select stdRegno,Stdname,Fname,Rollno,Dept,Session from student where stdRegno ='" & srcstudent.Text & "' Or Stdname ='" & StrConv(srcstudent.Text, VbStrConv.ProperCase) & "'", con)

        Dim da As New SqlDataAdapter(cmd)
        Dim ds As New DataSet
        ds.Clear()
        da.Fill(ds)
        DataGridView1.DataSource = ds.Tables(0)
        DataGridView1.Show()
        imageshow()

        con.Close()

Hope it can help you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.