Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have an assignment that involves me creating a Spelling Bee Test. I need to display information from a single column but I want each row from that column to be assigned to separate textboxes. I can't seem to figure a away to actually do that. So Can you people help please.

What I have tried:

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace Spelling_Bee_Retry
{
    public partial class Student_Test : Form
    {
        public Student_Test()
        {
            InitializeComponent();
        }
        OleDbCommand cmd = new OleDbCommand();
        OleDbConnection con = new OleDbConnection();
        OleDbDataAdapter da;
        DataSet ds;
        DataRow dRow;

        int maxRows;

        Database_Connection objConnect = new Database_Connection();

        

        private void Student_Test_Load(object sender, EventArgs e)
        {
            con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source= Spelling Bee.accdb";//creates a connection with my access database
            cmd.Connection = con;

            con.Open();
            cmd.CommandText = "SELECT * FROM " + globalVariables.testName;//selects the testname according to my tablename from combobox
            cmd.ExecuteNonQuery();



            



            OleDbDataReader dr = cmd.ExecuteReader();

            if (dr.Read())
            {
                //These are my textboxes. The first textbox displays the information from the first row from the column, but the rest I can't figure it out.

                defbx1.Text = dr.GetValue(1).ToString(); 
                defbx2.Text = dr.GetValue(1).ToString();

            }

            con.Close();


        }
Posted
Updated 9-May-16 19:33pm
v2

1 solution

if you use
C#
cmd.ExecuteReader()
you have to use for each row of the query result
C#
reader.Read()


C#
reader.Read()
defbx1.Text = dr.GetValue(1).ToString(); 
reader.Read()
defbx2.Text = dr.GetValue(1).ToString();

...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900