3
我試了好幾次,使其工作,但它只是不填充與MySQL數據DataGridView的,這裏是我的代碼:填充的DataGridView與MySQL數據
string connectionString = "SERVER=localhost;DATABASE=shootsource;UID=root;PASSWORD=;";
string sql = "SELECT * FROM characters";
MySqlConnection connection = new MySqlConnection(connectionString);
connection.Open();
sCommand = new MySqlCommand(sql, connection);
sAdapter = new MySqlDataAdapter(sCommand);
sBuilder = new MySqlCommandBuilder(sAdapter);
sDs = new DataSet();
sAdapter.Fill(sDs, "characters");
sTable = sDs.Tables["characters"];
connection.Close();
dataGridView1.DataSource = sDs.Tables["characters"];
dataGridView1.ReadOnly = true;
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
它只顯示從mysql表中的列'字符':身份證,名稱,時間等...我怎麼能從數據庫中填充它?
這是問題的一個形象:
只顯示列**頭* *?你是這個意思嗎?你確定桌子上有數據嗎? – climbage
是啊有..是啊..這裏有一張圖片:http://www.picz.ro/index.php?id=1dc2d2d989590d263a979c7a097124a0 –
我看不出有什麼問題 – climbage