1
首先,這是我第一次嘗試C#。 我的問題是,無論我使用數據表,列表或mysqldatareader;該查詢只返回一個結果並且只返回該表的最後一個結果。C#.NET MySql只返回最後的結果
我的表值(西名字在前): 指數城市 1巴黎 2倫敦
我的C#最後一個碼企圖是:
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 MySql.Data;
using MySql.Data.MySqlClient;
namespace MySQL_Sample
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
//MySql connections
MySqlConnection connection;
string host;
string db;
string uid;
string pass;
host = "localhost";
db = "sample";
uid = "root";
pass = "";
string ConnectionString = "SERVER=" + host + ";" + "DATABASE=" + db + ";" + "UID=" + uid + ";" + "PASSWORD=" + pass + ";";
connection = new MySqlConnection(ConnectionString);
connection.Open();
//MySql Commands
string sql = "SELECT * FROM table1";
MySqlCommand cmd = new MySqlCommand(sql, connection);
MySqlDataReader rdr = cmd.ExecuteReader();
//MySql Call back
while(rdr.Read())
{
DataTxtBox.Text = rdr[0].ToString() + " | " + rdr[1].ToString();
}
}
}
}
這是完美的;還要注意, DataTxtBox.Text + = rdr [0] .ToString()+「|」+ rdr [1] .ToString(); 已更改爲: DataTxtBox.Text + = rdr [0] .ToString()+「|」+ rdr [1] .ToString()+「\ r \ n」; – 2013-03-03 18:57:52