刚刚开始编写C#代码,我对此绝对是初学者.话虽如此,我对使用MySqlConnector和mysql查询有疑问.
我目前有一个查询,并用它填充结果的列表框.但是我想做的是向阅读器添加更多查询,并将其他查询的结果放入组合框.那么我该怎么做呢?我搜索了google,找不到答案.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace Badminton_stand
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
labelCurrentTime.Text = DateTime.Now.ToString();
}
private void Form1_Load(object sender, EventArgs e)
/* {
string MyConString = "Server=localhost;Port=3307;Database=database1;UID=root;Password=toor";
MySqlConnection connection = new MySqlConnection(MyConString);
MySqlCommand command = connection.CreateCommand();
MySqlDataReader Reader;
command.CommandText = @"select Club from teams;
select team from teams";
connection.Open();
Reader = command.ExecuteReader();
while (Reader.Read())
{
string thisrow = "";
for (int i = 0; i < Reader.FieldCount; i++)
thisrow += Reader.GetValue(i).ToString() + " ";
clubSelectorBox1.Items.Add(thisrow);
}
while (Reader.NextResult()) ;
{
string thisrow = "";
for (int i = 0; i < Reader.FieldCount; i++)
thisrow += Reader.GetValue(i).ToString() + " ";
cbTeam1.Items.Add(thisrow);
}
connection.Close();
} */
{
string cmdText = @"SELECT Club from teams;
SELECT team from teams";
using (MySqlConnection cnn = new MySqlConnection("Server=localhost;Port=3307;Database=badminton;UID=root;Password=usbw"))
using (MySqlCommand cmd = new MySqlCommand(cmdText, cnn))
{
cnn.Open();
using (MySqlDataReader reader = cmd.ExecuteReader())
{
do
{
while (reader.Read())
{
string thisrow = "";
for (int i = 0; i < reader.FieldCount; i++)
thisrow += reader.GetValue(i).ToString() + " ";
clubSelectorBox1.Items.Add(thisrow);
}
}
while (reader.NextResult());
{
}
}
}
}
}
}
提前致谢!