Search and Navigate!

Last post 07-09-2009 2:35 AM by Rangapure.S.Swapnil. 6 replies.

Sort Posts:

  • Search and Navigate!

    07-08-2009, 10:22 PM
    • Member
      point Member
    • jeff87
    • Member since 06-19-2009, 2:23 AM
    • Posts 15

    I am doing search function and navigate those record into related textboxes....but i can't make it work....since i use to code in VB.net,so i use the method that i was used in vb.net.....here is code that i use but its not work....please help!!!thank you!!

     
            con.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Jeff\Documents\Visual Studio 2008\WebSites\WebSite6\App_Data\KindergartenSQL.mdf;Integrated Security=True;User Instance=True"
            con.Open()
          
            sql = "SELECT * FROM Login"
            da = New SqlDataAdapter(sql, con)
          
            da.Fill(ds, "Login")
       
            con.Close()
            maxrows1 = ds.Tables("Login").Rows.Count
            
            inc = 0

     

            con.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Jeff\Documents\Visual Studio 2008\WebSites\WebSite6\App_Data\KindergartenSQL.mdf;Integrated Security=True;User Instance=True"

            con.Open()


          

            sql = "SELECT * FROM Login"


            da = New SqlDataAdapter(sql, con)

          

            da.Fill(ds, "Login")

       


            con.Close()


            maxrows1 = ds.Tables("Login").Rows.Count

            

            inc = 0

    end sub

    Sub navigate1()

            Dim ds As New DataSet

            Dim inc As Integer

            Dim Kindergarten As New DataTable

            TextBox1.Text = ds.Tables("Login").Rows(inc).Item(0)

            TextBox2.Text = ds.Tables("Login").Rows(inc).Item(1)

            

        End Sub


     Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)

            Dim C As String

            Dim c1 As Integer

            Dim CustomerFound As Boolean = False

            Dim ds As New DataSet

            Dim inc As Integer

            Dim maxrows1 As Integer

            Dim Kindergarten As New DataTable

            

            

            C = TextBox1.Text


            For c1 = 0 To (maxrows1 - 1)

                If CStr(ds.Tables("Login").Rows(c1)(0)) = C Then

                    CustomerFound = True

                    inc = c1

                    navigate1()



                End If

            Next

        End Sub

    Filed under:
  • Re: Search and Navigate!

    07-09-2009, 12:54 AM

    First of all , instead of using:

    con.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Jeff\Documents\Visual Studio 2008\WebSites\WebSite6\App_Data\KindergartenSQL.mdf;Integrated Security=True;User Instance=True"

    Use:

    <add name="myconn" connectionString="Data Source=localhost; Initial Catalog=KindergartenSQL;User ID=sa;Password=yourpassword"/>


    Secondly:


    I don't see that you are opening the connection in your code ,

    you haven't used con.open();




    Saurabh Nijhawan(B.Tech. CSE,GGSIPU,New Delhi)
    Application Architect, Eminent Solutions, New Delhi.
    Freelancer | Teacher
    Remember to click "Mark as Answer" on the post, if it helped you.
    ASP.NET Weblog
    http://www.saurabhnijhawan.com
    Learning Made Easy


  • Re: Search and Navigate!

    07-09-2009, 2:01 AM
    • Member
      448 point Member
    • Deeno20
    • Member since 03-25-2009, 7:21 AM
    • Kumavat
    • Posts 234

    hi

    first check Yor connection string

    To add correct connection string  just go to toos inmenu bar

    there is option called Connect to data base click on it

    then add connection window will open

    then chose the server name

    then chose correct Data base then click on test connection to check connection and also click advanced before click ok here u will get ur desired connection string

    justadd this connection string and check if get other error just let me know

    Happy TO Help
  • Re: Search and Navigate!

    07-09-2009, 2:05 AM
    • Member
      point Member
    • jeff87
    • Member since 06-19-2009, 2:23 AM
    • Posts 15

    thanks for your reply!i did use con.open() please see carefully!thank you!

    Filed under:
  • Re: Search and Navigate!

    07-09-2009, 2:11 AM
    • Member
      point Member
    • jeff87
    • Member since 06-19-2009, 2:23 AM
    • Posts 15

    test connection succeeded.

    Filed under:
  • Re: Search and Navigate!

    07-09-2009, 2:26 AM
    • Member
      448 point Member
    • Deeno20
    • Member since 03-25-2009, 7:21 AM
    • Kumavat
    • Posts 234

    Hi

    So u add that new connection string in ur application

    just tell me it is succeeded its good click on advanced button just above the test connection u will get the correct connection string

    add that one and let me know the next problrm if u r facing


    Happy TO Help
  • Re: Search and Navigate!

    07-09-2009, 2:35 AM
    Answer

    con.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Jeff\Documents\Visual Studio 2008\WebSites\WebSite6\App_Data\KindergartenSQL.mdf;Integrated Security=True;User Instance=True"

            con.Open()

           sql = "SELECT * FROM Login"

            da = New SqlDataAdapter(sql, con)

            da.Fill(ds, "Login")

     

    u have declared datset on button click,and using it on page_load..declare dataset  globally..

Page 1 of 1 (7 items)