could you please tell i am stuck here past 15 days.please
And when click to a particular button which display the option match with database to a 6 column of a every row if its is correct then backcolor of button is green else red.
thank you in advance.
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 WindowsFormsApplication3
{
public partial class Form1 : Form
{
public DataSet ds;
public OleDbDataAdapter adp;
OleDbConnection cn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\\C#\\Database1.accdb");
public Form1()
{
InitializeComponent();
}
private void button5_Click(object sender, EventArgs e)
{
cn.Open();
OleDbDataReader odr;
OleDbCommand cmd = new OleDbCommand("select * from QUESTION where[Type]=@en", cn);
cmd.Parameters.AddWithValue("@en", textBox3.Text);
odr = cmd.ExecuteReader();
odr.Read();
if (odr.HasRows)
{
textBox2.Text = odr[0].ToString();
textBox1.Text = odr[1].ToString();
button1.Text = odr[2].ToString();
button2.Text = odr[3].ToString();
button3.Text = odr[4].ToString();
button4.Text = odr[5].ToString();
}
else
{
MessageBox.Show("HEhehehehehe");
}
cn.Close();
}
}
}

VulpesRank #55 · 29.2K reputationPosted Mar 20, 2014, 8:26 AM EDT
VulpesRank #55 · 29.2K reputationPosted Mar 18, 2014, 9:13 AM EDT
Ajay Kadian128 reputationPosted Mar 18, 2014, 9:41 AM EDT
VulpesRank #55 · 29.2K reputationPosted Mar 18, 2014, 10:05 AM EDT
ds = new DataSet();
Ajay Kadian128 reputationPosted Mar 18, 2014, 10:20 AM EDT
Thanks very very very very much...
Ajay Kadian128 reputationPosted Mar 18, 2014, 10:56 AM EDT
I write a code but it didn't display answer in synchronize manner it differ from question what should i do.Please reply soon.
Thanks.
private void button9_Click(object sender, EventArgs e)
{
if (rowNumber > -1)
{
DataRow dr = ds.Tables[0].Rows[rowNumber];
label4.Text = dr[6].ToString();
rowNumber++;
if (rowNumber == ds.Tables[0].Rows.Count)
{
MessageBox.Show("No more questions left - starting again at beginning");
rowNumber = 0;
}
}
VulpesRank #55 · 29.2K reputationPosted Mar 18, 2014, 11:48 AM EDT
VulpesRank #55 · 29.2K reputationPosted Mar 18, 2014, 11:55 AM EDT
Add another field to store the current answer and change the other methods as follows:
private string answer;
private void button5_Click(object sender, EventArgs e)
{
if (rowNumber > -1)
{
DataRow dr = ds.Tables[0].Rows[rowNumber];
textBox2.Text = dr[0].ToString();
textBox1.Text = dr[1].ToString();
button1.Text = dr[2].ToString();
button2.Text = dr[3].ToString();
button3.Text = dr[4].ToString();
button4.Text = dr[5].ToString();
answer = dr[6].ToString();
rowNumber++;
if (rowNumber == ds.Tables[0].Rows.Count)
{
MessageBox.Show("No more questions left - starting again at beginning");
rowNumber = 0;
}
}
}
private void button9_Click(object sender, EventArgs e)
{
if (answer != null) label4.Text = answer; //EDITED
}
Ajay Kadian128 reputationPosted Mar 18, 2014, 12:48 PM EDT
I have an idea i am displaying 4 option on 4 different buttons if user click any button then the on click event its checks with answer in database if its is correct then backcolor of button is turn to green else red and then we click on button to show answer which i we already done.Can this be possible.
VulpesRank #55 · 29.2K reputationPosted Mar 18, 2014, 1:30 PM EDT
Ajay Kadian128 reputationPosted Mar 18, 2014, 6:47 PM EDT
i have 4 option which was displayed on 4 different button(button1,2,3,4) & the user press button2 then it checks that answer is whether right or wrong if wrong then backcolor is red else green then we click 9button which display answer in label.
Ajay Kadian128 reputationPosted Mar 18, 2014, 6:53 PM EDT
if(textBox4.Text.Trim().ToLower() == answer.Text.Trim().ToLower()) (==asnwer.text).
IIf i clicked button its backcolor changes when i move to next question the backcolor remain red i want when i move to next question the color changes to default.
VulpesRank #55 · 29.2K reputationPosted Mar 19, 2014, 2:34 AM EDT
private button2_Click(object sender, EventArgs e) // now button2_Click
{
if(textBox4.Text.Trim().ToLower() == answer.Trim().ToLower())
{
button2.BackColor = Color.Green;
}
else
{
button2.BackColor = Color.Red;
}
button9.PerformClick();
}
BTW, I'm applying Trim() and ToLower() to both strings to make sure that the user won't be regarded as giving a wrong answer just because of a difference in capitalization and/or leading/trailing whitespace.
We also need to change button5_Click:
private void button5_Click(object sender, EventArgs e)
{
if (rowNumber > -1)
{
DataRow dr = ds.Tables[0].Rows[rowNumber];
textBox2.Text = dr[0].ToString();
textBox1.Text = dr[1].ToString();
button1.Text = dr[2].ToString();
button2.Text = dr[3].ToString();
button3.Text = dr[4].ToString();
button4.Text = dr[5].ToString();
answer = dr[6].ToString();
button2.BackColor = button2.DefaultBackColor;
rowNumber++;
if (rowNumber == ds.Tables[0].Rows.Count)
{
MessageBox.Show("No more questions left - starting again at beginning");
rowNumber = 0;
}
}
}
Ajay Kadian128 reputationPosted Mar 19, 2014, 4:48 AM EDT
so what else i use here.
It doesn't work because when i clicked any one from the four buttons if whether answer is write or wrong its shows red its color doesn't change.
VulpesRank #55 · 29.2K reputationPosted Mar 19, 2014, 5:13 AM EDT
So replace it with whatever textbox is being used for this purpose.
Ajay Kadian128 reputationPosted Mar 19, 2014, 6:43 AM EDT
VulpesRank #55 · 29.2K reputationPosted Mar 19, 2014, 7:43 AM EDT
Ajay Kadian128 reputationPosted Mar 19, 2014, 8:12 AM EDT
It didn't work :( when i click a correct answer then the color changes to red and i want if the text of button match with the text of label4 then backcolor of button changes to green else red.I am storing my answer label4 which is evoke on button9.PerformClick(); .
VulpesRank #55 · 29.2K reputationPosted Mar 19, 2014, 1:11 PM EDT
Ajay Kadian128 reputationPosted Mar 20, 2014, 3:10 AM EDT
VulpesRank #55 · 29.2K reputationPosted Mar 20, 2014, 3:22 AM EDT
private button1_Click(object sender, EventArgs e)
{
string msg = String.Format("button text = {0} (length = {1})\r\nanswer = {2} (length = {3}", button1.Text, button1.Text.Length, answer, answer.Length);
MessageBox.Show(msg);
button1.BackColor = (button1.Text == answer) ? Color.Green : Color.Red;
button9.PerformClick();
}
Now pick a question where button1 gives the correct answer and tell me what you see in the messagebox.
Ajay Kadian128 reputationPosted Mar 20, 2014, 3:50 AM EDT
VulpesRank #55 · 29.2K reputationPosted Mar 20, 2014, 4:10 AM EDT
So it looks like there's some white-space which we need to trim off before making the comparison:
and similarly for the other three buttons.
If that still doesn't work, then the 'surplus' characters must be nulls and we'll need to use a different overload of Trim to get rid of those.
Ajay Kadian128 reputationPosted Mar 20, 2014, 4:22 AM EDT
Thanks very very much...
Can i ask another question related to this ;)
VulpesRank #55 · 29.2K reputationPosted Mar 20, 2014, 5:56 AM EDT
Ajay Kadian128 reputationPosted Mar 20, 2014, 6:18 AM EDT
Thanks
Ajay Kadian128 reputationPosted Mar 20, 2014, 9:08 AM EDT
Finally my app in final steps last phase i really appreciate your work again thank you very much.
Thanks very very much :) :) :) ...
Ajay Kadian128 reputationPosted Mar 22, 2014, 7:58 AM EDT
VulpesRank #55 · 29.2K reputationPosted Mar 22, 2014, 9:33 AM EDT