C# Database Question and Answers Connect
-
I created one table like this: CREATE TABLE Pitanja ( ID int NOT NULL IDENTITY (1,1) PRIMARY KEY, Pitanje nvarchar(1000) NOT NULL, Odgovor int NOT NULL, OpcijaA nvarchar(1000) NOT NULL, OpcijaB nvarchar(1000) NOT NULL, OpcijaC nvarchar(1000) NOT NULL, OpcijaD nvarchar(1000) NOT NULL ); This is one part of table Pitanja INSERT INTO Pitanja(Pitanje,Odgovor,OpcijaA,OpcijaB,OpcijaC,OpcijaD) VALUES('Blizu kog grada se nalaze Sremski Karlovci',3,'Rume','Sremske Mitrovice','Novog Sada','Šida'); Answers column contains number of correct choice,not word of correct choice.How to check answer when user select one of four choices from four buttons?
-
I created one table like this: CREATE TABLE Pitanja ( ID int NOT NULL IDENTITY (1,1) PRIMARY KEY, Pitanje nvarchar(1000) NOT NULL, Odgovor int NOT NULL, OpcijaA nvarchar(1000) NOT NULL, OpcijaB nvarchar(1000) NOT NULL, OpcijaC nvarchar(1000) NOT NULL, OpcijaD nvarchar(1000) NOT NULL ); This is one part of table Pitanja INSERT INTO Pitanja(Pitanje,Odgovor,OpcijaA,OpcijaB,OpcijaC,OpcijaD) VALUES('Blizu kog grada se nalaze Sremski Karlovci',3,'Rume','Sremske Mitrovice','Novog Sada','Šida'); Answers column contains number of correct choice,not word of correct choice.How to check answer when user select one of four choices from four buttons?
You could put the answers into an array like so:
string[] Answers = new string[4];
//
//Code to load answers into array
//
string UserChoice = Answers[IndexOfChoice];Just set the variable
IndexOfChoice
to a number from 0 to 3 depending upon which button was clicked.IndexOfChoice
is an int.The difficult we do right away... ...the impossible takes slightly longer.
-
You could put the answers into an array like so:
string[] Answers = new string[4];
//
//Code to load answers into array
//
string UserChoice = Answers[IndexOfChoice];Just set the variable
IndexOfChoice
to a number from 0 to 3 depending upon which button was clicked.IndexOfChoice
is an int.The difficult we do right away... ...the impossible takes slightly longer.
Here is complete code:
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\[th
-
Here is complete code:
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\[th
Who's writing this application, you or us? How do you think you should shuffle the cards?
This space for rent
-
Who's writing this application, you or us? How do you think you should shuffle the cards?
This space for rent
I am creating new database.This is one part of it: {"a1":"Kina","a2":"Berlin","a3":"Živi","a4":"Cigla","a5":["Zid"],"b1":"Rešetke","b2":"Kriminal","b3":"Alkatraz","b4":"Kaucija","b5":["Zatvor"],"c1":"Artiljerija","c2":"Volt","c3":"Naboj","c4":"AA","c5":["Baterija","baterije"],"d1":"Bubreg","d2":"Nadležni","d3":"Tkivo","d4":"Transplantacija","d5":["Organ"],"rr":["Ćelija","ćelijski","celija","celijski"]} How to make all this as answer inside column Answers: ["Ćelija","ćelijski","celija","celijski"]
-
I am creating new database.This is one part of it: {"a1":"Kina","a2":"Berlin","a3":"Živi","a4":"Cigla","a5":["Zid"],"b1":"Rešetke","b2":"Kriminal","b3":"Alkatraz","b4":"Kaucija","b5":["Zatvor"],"c1":"Artiljerija","c2":"Volt","c3":"Naboj","c4":"AA","c5":["Baterija","baterije"],"d1":"Bubreg","d2":"Nadležni","d3":"Tkivo","d4":"Transplantacija","d5":["Organ"],"rr":["Ćelija","ćelijski","celija","celijski"]} How to make all this as answer inside column Answers: ["Ćelija","ćelijski","celija","celijski"]
That is not a database. That is a fragment of JSON, and should be treated as such.
This space for rent