C#返回mysql查询结果_c#查询MySQL是怎么接收返回结果的
剛找了個例子,是下面的代碼片段。來自?http://blog.csdn.net/u010580422/article/details/45851237
關于最后兩行代碼有點問題
1、fill?函數似乎是填充一個結果集緩沖區,也就是這里的?ds?變量,那后面的字符串參數是什么
2、最后一行似乎是求數組的元素,那個數組怎么用字符串做索引
3、最主要的就是?select?*?from?table?的結果集,怎么讀取每一行每一列的字符串
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.MySqlClient;
using?System.Data.SqlClient;
namespace?mysqltest1
{
public?partial?class?Form1?:?Form
{
public?Form1()
{
InitializeComponent();
}
private?void?button1_Click(object?sender,?EventArgs?e)
{
string?strConn?=?"server=localhost;User?Id=root;password=;Database=cshape;Charset=utf8";
MySqlConnection?conn?=?new?MySqlConnection(strConn);
conn.Open();//鏈接數據庫
DataSet?ds?=?new?DataSet();
string?sql?=?"select?*?from?list_class1_submit";
MySqlDataAdapter?da?=?new?MySqlDataAdapter(sql,?conn);
da.Fill(ds,?"table");
dataGridView1.DataSource?=?ds.Tables["table"];
}
}
}
解決方案
2
和你操作SQL?Server一樣。
9
9
ds是dataset,數據集,集,即表的集合,可以看做一個內存數據庫,可以包含許多張表。
da.Fill(ds,?“table”);??//把da的查詢結果(是一個臨時table)填充到ds,在ds里面索引名字是”table”。
dataGridView1.DataSource?=?ds.Tables[“table”];//表格控件綁定數據源為ds的table表。
CodeBye 版權所有丨如未注明 , 均為原創丨本網站采用BY-NC-SA協議進行授權 , 轉載請注明c#查詢MySQL是怎么接收返回結果的!
總結
以上是生活随笔為你收集整理的C#返回mysql查询结果_c#查询MySQL是怎么接收返回结果的的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MySQL批量查询能返回集合吗_JDBC
- 下一篇: express与mysql数据库_exp