Click here to Skip to main content
15,886,110 members
Home / Discussions / C#
   

C#

 
AnswerRe: adding data to database from combobox Pin
Alex Manolescu30-Jan-10 2:53
Alex Manolescu30-Jan-10 2:53 
GeneralRe: adding data to database from combobox Pin
Erdinc2730-Jan-10 3:33
Erdinc2730-Jan-10 3:33 
GeneralRe: adding data to database from combobox Pin
Alex Manolescu30-Jan-10 4:49
Alex Manolescu30-Jan-10 4:49 
GeneralRe: adding data to database from combobox Pin
Erdinc2730-Jan-10 23:53
Erdinc2730-Jan-10 23:53 
GeneralRe: adding data to database from combobox Pin
Alex Manolescu31-Jan-10 8:51
Alex Manolescu31-Jan-10 8:51 
GeneralRe: adding data to database from combobox Pin
Erdinc2731-Jan-10 21:27
Erdinc2731-Jan-10 21:27 
GeneralRe: adding data to database from combobox Pin
Alex Manolescu31-Jan-10 21:35
Alex Manolescu31-Jan-10 21:35 
QuestionShowing data from a database to a listbox during runtime Pin
gamer112729-Jan-10 23:47
gamer112729-Jan-10 23:47 
Hi. I'm having problems in showing all the data to a listbox. all of the data will be coming from a database and will be shown depending on the choices of the user. i tried to code it but it didn't work. here's my code:


public frmMainForm()
        {
            InitializeComponent();
            string sConnection = "Provider = Microsoft.Jet.OLEDB.4.0;" + "Data Source = Schedule.mdb";

            using (OleDbConnection dbConnect = new OleDbConnection(sConnection))
            {
                dbConnect.Open();

                if (prog == "CS")
                {
                    string sqlString = "SELECT cs_firstcourse, cs_secondcourse, cs_thirdcourse, cs_fourthcourse, cs_fifthcourse, cs_sixthcourse, cs_seventhcourse, cs_eighthcourse, cs_ninthcourse FROM CS WHERE cs_year = @chosenYear AND cs_term = @chosenTerm;";

                    OleDbCommand dbCmd = new OleDbCommand();
                    dbCmd.CommandText = sqlString;
                    dbCmd.Connection = dbConnect;
                    dbCmd.Parameters.AddWithValue("chosenYear", chosenYear);
                    dbCmd.Parameters.AddWithValue("chosenTerm", choseTerm);

                    using (OleDbDataReader dbReader = dbCmd.ExecuteReader())
                    {
                        if (dbReader.Read() == true)
                        {
                            for (int a = 0; a < 9; a++)
                            {
                                lstBoxCourses.Items.Add(dbReader[a].ToString());
                            }
                        }
                        else
                        {
                            MessageBox.Show("An error has occured while trying to retrieve data from the database", "Class Scheduling: Database Access Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        dbReader.Close();
                    }
                }
                dbConnect.Close();
            }
        }



can someone help me?
AnswerRe: Showing data from a database to a listbox during runtime Pin
OriginalGriff29-Jan-10 23:52
mveOriginalGriff29-Jan-10 23:52 
JokeRe: Showing data from a database to a listbox during runtime Pin
DaveyM6930-Jan-10 0:09
professionalDaveyM6930-Jan-10 0:09 
GeneralRe: Showing data from a database to a listbox during runtime Pin
OriginalGriff30-Jan-10 0:22
mveOriginalGriff30-Jan-10 0:22 
GeneralOT Pin
DaveyM6930-Jan-10 2:01
professionalDaveyM6930-Jan-10 2:01 
GeneralRe: Showing data from a database to a listbox during runtime Pin
gamer112730-Jan-10 2:15
gamer112730-Jan-10 2:15 
GeneralRe: Showing data from a database to a listbox during runtime Pin
OriginalGriff30-Jan-10 2:27
mveOriginalGriff30-Jan-10 2:27 
GeneralRe: Showing data from a database to a listbox during runtime Pin
gamer112730-Jan-10 5:48
gamer112730-Jan-10 5:48 
GeneralRe: Showing data from a database to a listbox during runtime Pin
OriginalGriff30-Jan-10 5:58
mveOriginalGriff30-Jan-10 5:58 
GeneralRe: Showing data from a database to a listbox during runtime Pin
gamer112730-Jan-10 6:08
gamer112730-Jan-10 6:08 
AnswerRe: Showing data from a database to a listbox during runtime Pin
sanforjackass30-Jan-10 0:31
sanforjackass30-Jan-10 0:31 
QuestionQuestion about Session Pin
YiXiang_8929-Jan-10 22:20
YiXiang_8929-Jan-10 22:20 
AnswerRe: Question about Session [modified] Pin
sanforjackass29-Jan-10 22:36
sanforjackass29-Jan-10 22:36 
AnswerRe: Question about Session Pin
Nuri Ismail29-Jan-10 22:37
Nuri Ismail29-Jan-10 22:37 
GeneralRe: Question about Session Pin
YiXiang_8929-Jan-10 22:39
YiXiang_8929-Jan-10 22:39 
GeneralRe: Question about Session Pin
Nuri Ismail29-Jan-10 22:53
Nuri Ismail29-Jan-10 22:53 
Questionreply onlywe want Pin
Rajasara29-Jan-10 20:24
Rajasara29-Jan-10 20:24 
AnswerRe: reply onlywe want Pin
Dan Mos29-Jan-10 20:43
Dan Mos29-Jan-10 20:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.