Click here to Skip to main content
15,887,485 members
Home / Discussions / C#
   

C#

 
GeneralRe:I can not understand the error.....code bellow...for trans data from sql database to another Pin
OriginalGriff25-Dec-16 23:41
mveOriginalGriff25-Dec-16 23:41 
GeneralRe: I can not understand the error.....code bellow...for trans data from sql database to another Pin
Gerry Schmitz26-Dec-16 6:01
mveGerry Schmitz26-Dec-16 6:01 
QuestionThe programming webcam with Visual Studio standard library ? Pin
Member 245846725-Dec-16 19:42
Member 245846725-Dec-16 19:42 
AnswerRe: The programming webcam with Visual Studio standard library ? Pin
Richard MacCutchan25-Dec-16 20:38
mveRichard MacCutchan25-Dec-16 20:38 
GeneralRe: The programming webcam with Visual Studio standard library ? Pin
Member 245846728-Dec-16 15:51
Member 245846728-Dec-16 15:51 
QuestionC# Database Question and Answers Connect Pin
Pavlex425-Dec-16 3:36
Pavlex425-Dec-16 3:36 
AnswerRe: C# Database Question and Answers Connect Pin
Richard Andrew x6425-Dec-16 5:24
professionalRichard Andrew x6425-Dec-16 5:24 
GeneralRe: C# Database Question and Answers Connect Pin
Pavlex425-Dec-16 7:02
Pavlex425-Dec-16 7:02 
Here is complete code:

C#
int QuesionCount;
        int IndexOfChoice;
        DataTable dt = new DataTable();
        int[] Answers = new int[4];
        string cs= @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=c:\users\pavle\documents\visual studio 2015\Projects\Ko zna zna\Ko zna zna\Koznazna.mdf;Integrated Security=True";
        private void Form1_Load(object sender, EventArgs e)
        {
            using (SqlConnection connection = new SqlConnection(cs))
            {
                string query = "SELECT * FROM Pitanja ORDER BY NEWID()";
                SqlCommand command = new SqlCommand(query, connection);
                try
                {
                    connection.Open();
                    dt.Load(command.ExecuteReader());
                    connection.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }  
            }
            setQuestion();
        }

        private void provera()
        {
            int UserChoice = Answers[IndexOfChoice];
            if (answer_id == UserChoice)
            {
                MessageBox.Show("Odgovor je tacan!");
            }
            else
            {
                MessageBox.Show("Odgovor nije tacan!");
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Answers[IndexOfChoice] = 1;
            provera();  
        }
       
        private void button2_Click(object sender, EventArgs e)
        {
            Answers[IndexOfChoice] = 2;
            provera();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Answers[IndexOfChoice] = 3;
            provera();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            Answers[IndexOfChoice] = 4;
            provera();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            try
            {
                this.QuesionCount++;
                setQuestion();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        int answer_id;
        private void setQuestion()
        { 
            try
            {
                this.label2.Text = this.dt.Rows[this.QuesionCount]["Pitanje"].ToString();
                this.button1.Text = this.dt.Rows[this.QuesionCount]["OpcijaA"].ToString();
                this.button2.Text = this.dt.Rows[this.QuesionCount]["OpcijaB"].ToString();
                this.button3.Text = this.dt.Rows[this.QuesionCount]["OpcijaC"].ToString();
                this.button4.Text = this.dt.Rows[this.QuesionCount]["OpcijaD"].ToString();
                
                this.label3.Text = this.dt.Rows[this.QuesionCount]["Odgovor"].ToString();        
                answer_id = Convert.ToInt32(this.dt.Rows[this.QuesionCount]["Odgovor"]);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }


How to shuffle choises and keep track of the correct solution?
GeneralRe: C# Database Question and Answers Connect Pin
Pete O'Hanlon25-Dec-16 9:57
mvePete O'Hanlon25-Dec-16 9:57 
GeneralRe: C# Database Question and Answers Connect Pin
Pavlex426-Dec-16 7:39
Pavlex426-Dec-16 7:39 
GeneralRe: C# Database Question and Answers Connect Pin
Pete O'Hanlon27-Dec-16 22:24
mvePete O'Hanlon27-Dec-16 22:24 
QuestionC# Read from text file Pin
Pavlex423-Dec-16 21:16
Pavlex423-Dec-16 21:16 
AnswerRe: C# Read from text file Pin
Michael_Davies23-Dec-16 21:29
Michael_Davies23-Dec-16 21:29 
AnswerRe: C# Read from text file Pin
OriginalGriff23-Dec-16 21:34
mveOriginalGriff23-Dec-16 21:34 
GeneralRe: C# Read from text file Pin
Pavlex423-Dec-16 21:40
Pavlex423-Dec-16 21:40 
AnswerRe: C# Read from text file Pin
Midi_Mick23-Dec-16 21:41
professionalMidi_Mick23-Dec-16 21:41 
GeneralRe: C# Read from text file Pin
Pavlex423-Dec-16 21:53
Pavlex423-Dec-16 21:53 
GeneralRe: C# Read from text file Pin
Midi_Mick23-Dec-16 22:09
professionalMidi_Mick23-Dec-16 22:09 
GeneralRe: C# Read from text file Pin
OriginalGriff23-Dec-16 22:56
mveOriginalGriff23-Dec-16 22:56 
GeneralRe: C# Read from text file Pin
Dave Kreskowiak24-Dec-16 4:38
mveDave Kreskowiak24-Dec-16 4:38 
AnswerRe: C# Read from text file Pin
Gerry Schmitz26-Dec-16 5:42
mveGerry Schmitz26-Dec-16 5:42 
QuestionC# Specified cast is not valid Pin
Pavlex422-Dec-16 20:48
Pavlex422-Dec-16 20:48 
AnswerRe: C# Specified cast is not valid Pin
Richard MacCutchan22-Dec-16 21:23
mveRichard MacCutchan22-Dec-16 21:23 
GeneralRe: C# Specified cast is not valid Pin
Pavlex422-Dec-16 21:33
Pavlex422-Dec-16 21:33 
GeneralRe: C# Specified cast is not valid Pin
Richard MacCutchan22-Dec-16 22:09
mveRichard MacCutchan22-Dec-16 22:09 

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.