Answer the question
In order to leave comments, you need to log in
How to separate the data received by the query into different forms?
I have 3 tables.
questions answers
subjects By
this query
SELECT questions.question_text, answers.answer_1, answers.answer_2, answers.answer_3, answers.answer_4 FROM questions JOIN answers ON answers.ID = questions.ID_answer
I post questions and answers. namespace WindowsFormsApp1
{
public partial class ListItemTest : UserControl
{
public ListItemTest()
{
InitializeComponent();
}
#region Proporties
private string _question;
private string _answer1;
private string _answer2;
private string _answer3;
private string _answer4;
[Category("Custom Props")]
public string Question
{
get { return _question; }
set { _question = value; lbl_question.Text = value; }
}
[Category("Custom Props")]
public string Answer1
{
get { return _answer1; }
set { _answer1 = value; rb_answer1.Text = value; }
}
[Category("Custom Props")]
public string Answer2
{
get { return _answer2; }
set { _answer2 = value; rb_answer2.Text = value; }
}
[Category("Custom Props")]
public string Answer3
{
get { return _answer3; }
set { _answer3 = value; rb_answer3.Text = value; }
}
[Category("Custom Props")]
public string Answer4
{
get { return _answer4; }
set { _answer4 = value; rb_answer4.Text = value; }
}
#endregion
}
}
private void LastNumber()
{
string connStr = "server=localhost; port=3306; username=root; password= root; database=vedar_bd";
string sql = "SELECT COUNT(DISTINCT question_text) FROM questions";
// string sql = "SELECT * FROM Table WHERE Field IN (SELECT Field FROM Table GROUP BY Field HAVING COUNT(*) > 1)";
MySqlConnection conn = new MySqlConnection(connStr);
conn.Open();
MySqlCommand command = new MySqlCommand(sql, conn);
string number = command.ExecuteScalar().ToString();
int xnumber = int.Parse(number);
SubjNumber = xnumber;
}
private void OneTest()
{
string connStr = "server=localhost; port=3306; username=root; password= root; database=vedar_bd";
string sql = "SELECT questions.question_text, answers.answer_1, answers.answer_2, answers.answer_3, answers.answer_4 " +
"FROM questions JOIN answers ON answers.ID = questions.ID_answer";
MySqlConnection conn = new MySqlConnection(connStr);
conn.Open();
MySqlCommand command = new MySqlCommand(sql, conn);
MySqlDataReader SomeTest;
DataTable tableTest = new DataTable();
SomeTest = command.ExecuteReader();
tableTest.Load(SomeTest);
ListItemTest[] listitems = new ListItemTest[SubjNumber];
for (int i = 0; i < SubjNumber; i++)
{
listitems[i] = new ListItemTest();
listitems[i].Question = tableTest.Rows[i][0].ToString();
listitems[i].Answer1 = tableTest.Rows[i][1].ToString();
listitems[i].Answer2 = tableTest.Rows[i][2].ToString();
listitems[i].Answer3 = tableTest.Rows[i][3].ToString();
listitems[i].Answer4 = tableTest.Rows[i][4].ToString();
if (flowLayoutPanel1.Controls.Count < 0)
{
flowLayoutPanel1.Controls.Clear();
}
else
flowLayoutPanel1.Controls.Add(listitems[i]);
}
conn.Close();
}
private void Frm_TestView_Load(object sender, EventArgs e)
{
LastNumber();
OneTest();
}
Answer the question
In order to leave comments, you need to log in
How to separate the data received by the query into different forms?but you don’t need to divide,
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question