我对编程领域很陌生,比如4个月新编,所以我觉得99%的人都有一个非常愚蠢的问题。
我正在忙着创建一个非常基本的预约程序来练习,并且像疯猪一样苦苦挣扎。
1)我基本上想把数据从MySql拉到文本框 2)我的目标是我需要获取一个循环,将预订ID保存在MySql中。不确定你们是否都能理解我的意思。
当前代码:
string connection = "datasource = localhost; port = 3306; username = root; password = ****";
string query = "SELECT * FROM databasename.tablename where id='"this.textbox1.Text"' ";
MySqlConnection conn = new MySqlConnection(connection);
MySqlCommand command = new MySqlCommand(query, conn);
MySqlDataReader reader;
conn.Open();
reader = command.ExecuteReader();
while (reader.Read())
{
}
答案 0 :(得分:0)
只需使用parameters
:
string connection = "datasource = localhost; port = 3306; username = root; password = ****";
string query = "SELECT * FROM databasename.tablename where id=@ID ";
MySqlConnection conn = new MySqlConnection(connection);
MySqlCommand command = new MySqlCommand(query, conn);
command.Parameters.Add("@ID",textBox1.Text);
MySqlDataReader reader;
conn.Open();
reader = command.ExecuteReader();
while (reader.Read()) {}