locked
next question in database? RRS feed

  • Question

  • User574909881 posted

     I have 5 question in my database.

    The table is called Kysymys and there is:

    Kysymys

    Mitä kuuluu?

    Onko kivaa?

    Oletko masentunut

    etc.

     

    i have the code for reading the first line ( Mitä kuuluu?), what do I have to do to get it read the next line?

     private void button1_Click(object sender, EventArgs e)
            {
                OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\koulu\Tietokanta1.mdb;");
                OleDbCommand cmd = new OleDbCommand();

                try
                {
                    conn.Open();
                    cmd.Connection = conn;
                    cmd.CommandText = "SELECT Kysymys FROM Tietokanta";
                    using (OleDbDataReader dr = cmd.ExecuteReader())
                    {
                        // Skip to first record.
                        dr.Read();
                        // Read first column (Kysymys).
                        textBox1.Text = dr.GetString(0);    // this reads the Mitä kuuluu?             
                      
                        
                        
                    }
                }
                catch (OleDbException oledbEx)
                {
                    System.Diagnostics.Debug.WriteLine("oledbEx.Message=" + oledbEx.Message);
                    if (null != oledbEx.InnerException)
                    {
                        System.Diagnostics.Debug.WriteLine("oledbEx.InnerException.Message=" + oledbEx.InnerException.Message);
                    }
                }
                conn.Close();
            }

     

     

    Monday, October 20, 2008 5:46 AM

Answers

  • User535082756 posted

    hi

    check the below link for further details ...happy coding...

    http://msdn.microsoft.com/en-us/library/haa3afyz(VS.80).aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 20, 2008 5:56 AM
  • User-1199946673 posted

    You don't have to code anything, just use a detailsview: put the database in the App_Data folder inside the root of the website. Place the following HTML markup in the page and that's it:

     

        <asp:DetailsView
            ID="DetailsView1"
            runat="server"
            AllowPaging="True" 
            DataSourceID="AccessDataSource1">
            <PagerSettings
                Mode="NextPrevious"
                NextPageText="Next" 
                PreviousPageText="Previous" />
        </asp:DetailsView>
        <asp:AccessDataSource
            ID="AccessDataSource1"
            runat="server" 
            DataFile="~/App_Data/Tietokanta1.mdb" 
            SelectCommand="SELECT [Kysymys] FROM [Tietokanta]">
        </asp:AccessDataSource>
    
     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 20, 2008 8:56 AM

All replies

  • User535082756 posted

    hi

    check the below link for further details ...happy coding...

    http://msdn.microsoft.com/en-us/library/haa3afyz(VS.80).aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 20, 2008 5:56 AM
  • User574909881 posted

     i have made this:

                        if (dr.HasRows)
                        {
                            while (dr.Read())
                            {
                                 textBox1.Text = dr.GetString(0);

                                 // break;
                                
                            }

                            dr.NextResult();
                        }
                        else
                        {
                            MessageBox.Show("No rows found.");
                        }

     

     

    now it shows the last question in the database.

    What should I modify to show the first question when I click the button and when I click the button second time it shows the second question etc...?

     

    I added the break, it showed the first question but I tried to click the button again, it did nothing..

    Monday, October 20, 2008 6:59 AM
  • User-1199946673 posted

    You don't have to code anything, just use a detailsview: put the database in the App_Data folder inside the root of the website. Place the following HTML markup in the page and that's it:

     

        <asp:DetailsView
            ID="DetailsView1"
            runat="server"
            AllowPaging="True" 
            DataSourceID="AccessDataSource1">
            <PagerSettings
                Mode="NextPrevious"
                NextPageText="Next" 
                PreviousPageText="Previous" />
        </asp:DetailsView>
        <asp:AccessDataSource
            ID="AccessDataSource1"
            runat="server" 
            DataFile="~/App_Data/Tietokanta1.mdb" 
            SelectCommand="SELECT [Kysymys] FROM [Tietokanta]">
        </asp:AccessDataSource>
    
     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 20, 2008 8:56 AM