Exemplo n.º 1
0
        public void searchQuestionFromDatabase()
        {
            int QuestionSNo = 1;

            if (selectQuestionNoSystem == "Online")
            {
                QuestionSNo = InformationAnalysis.getQuestionNo();
            }
            else if (selectQuestionNoSystem == "Offline")
            {
                QuestionSNo = offlineInformationAnalysis.getQuestionNo();
            }



            // step 1: Create a connection
            var           result        = Path.GetFullPath("InformationDatabase.mdf");
            string        strConnection = "Data Source=.\\sqlexpress;AttachDbFilename=" + result + ";User Instance=true;Integrated Security=True;Pooling=False";
            SqlConnection objConnection = new SqlConnection(strConnection);

            objConnection.Open();


            try
            {
                // step 2: fire a command

                string     strCommand = "select PicURL from Question where QSN=" + QuestionSNo + "";
                SqlCommand objCommand = new SqlCommand(strCommand, objConnection);

                // step 3: bind the result data with user interface

                SqlDataReader reader = objCommand.ExecuteReader();

                reader.Read();



                byte[]       img = (byte[])(reader[0]);
                MemoryStream ms  = new MemoryStream(img);
                pictureBoxPic.Image = Image.FromStream(ms);



                objConnection.Close();
            }
            catch (Exception ex)
            {
                if (objConnection.State == ConnectionState.Open)
                {
                    objConnection.Close();
                }
            }
        }
        public void searchQuestionFromDatabase()
        {
            int QuestionSNo = 1;

            if (selectQuestionNoSystem == "Online")
            {
                QuestionSNo = InformationAnalysis.getQuestionNo();
            }
            else if (selectQuestionNoSystem == "Offline")
            {
                QuestionSNo = offlineInformationAnalysis.getQuestionNo();
            }

            QSN = QuestionSNo;

            // step 1: Create a connection
            var           result        = Path.GetFullPath("InformationDatabase.mdf");
            string        strConnection = "Data Source=.\\sqlexpress;AttachDbFilename=" + result + ";User Instance=true;Integrated Security=True;Pooling=False";
            SqlConnection objConnection = new SqlConnection(strConnection);

            objConnection.Open();


            try
            {
                // step 2: fire a command

                string     strCommand = "select * from Question where QSN=" + QuestionSNo + "";
                SqlCommand objCommand = new SqlCommand(strCommand, objConnection);

                // step 3: bind the result data with user interface

                SqlDataReader reader = objCommand.ExecuteReader();

                reader.Read();

                labelQSN.Text = reader[0].ToString();

                if (reader[2].ToString() == "NA")
                {
                    labelUpperText.Text = "";
                }
                else
                {
                    labelUpperText.Text = reader[2].ToString();
                }



                if (reader[6].ToString() == "NA")
                {
                    richTextBoxDescription.Text = "";
                }
                else
                {
                    richTextBoxDescription.Text = reader[6].ToString();
                }

                labelQuestion1.Text = reader[13].ToString();

                labelQuestion2.Text = reader[15].ToString();

                labelOptionA.Text = reader[16].ToString();
                labelOptionB.Text = reader[17].ToString();
                labelOptionC.Text = reader[18].ToString();
                labelOptionD.Text = reader[19].ToString();

                OptionA = reader[16].ToString();

                OptionB = reader[17].ToString();

                OptionC = reader[18].ToString();

                OptionD = reader[19].ToString();

                right_Answer1 = reader[14].ToString();
                right_Answer2 = reader[20].ToString();


                objConnection.Close();
            }
            catch (Exception ex)
            {
                if (objConnection.State == ConnectionState.Open)
                {
                    objConnection.Close();
                }

                // MessageBox.Show(ex.Message);
            }
        }