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();
}
}
}
VulpesPosted Mar 20, 2014, 12:26 PM
VulpesPosted Mar 22, 2014, 1:33 PM
Ajay KadianPosted Mar 22, 2014, 11:58 AM
Ajay KadianPosted Mar 20, 2014, 1:08 PM
Finally my app in final steps last phase i really appreciate your work again thank you very much.
Thanks very very much :) :) :) ...
Ajay KadianPosted Mar 20, 2014, 10:18 AM
Thanks
VulpesPosted Mar 20, 2014, 9:56 AM
Ajay KadianPosted Mar 20, 2014, 8:22 AM
Thanks very very much...
Can i ask another question related to this ;)
VulpesPosted Mar 20, 2014, 8:10 AM
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 KadianPosted Mar 20, 2014, 7:50 AM
VulpesPosted Mar 20, 2014, 7:22 AM
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 KadianPosted Mar 20, 2014, 7:10 AM
VulpesPosted Mar 19, 2014, 5:11 PM
Ajay KadianPosted Mar 19, 2014, 12:12 PM
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(); .
VulpesPosted Mar 19, 2014, 11:43 AM
Ajay KadianPosted Mar 19, 2014, 10:43 AM
VulpesPosted Mar 19, 2014, 9:13 AM
So replace it with whatever textbox is being used for this purpose.
Ajay KadianPosted Mar 19, 2014, 8:48 AM
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.
VulpesPosted Mar 19, 2014, 6:34 AM
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 KadianPosted Mar 18, 2014, 10:53 PM
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.
Ajay KadianPosted Mar 18, 2014, 10:47 PM
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.
VulpesPosted Mar 18, 2014, 5:30 PM
Ajay KadianPosted Mar 18, 2014, 4:48 PM
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.
VulpesPosted Mar 18, 2014, 3:55 PM
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
}
VulpesPosted Mar 18, 2014, 3:48 PM
Ajay KadianPosted Mar 18, 2014, 2:56 PM
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;
}
}
Ajay KadianPosted Mar 18, 2014, 2:20 PM
Thanks very very very very much...
VulpesPosted Mar 18, 2014, 2:05 PM
ds = new DataSet();
Ajay KadianPosted Mar 18, 2014, 1:41 PM
VulpesPosted Mar 18, 2014, 1:13 PM