c#查询MySQL是怎么接收返回结果的

谁学逆向工程 2016-10-20 11:42:31
刚找了个例子,是下面的代码片段。来自 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"];
}
}
}
...全文
856 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
谁学逆向工程 2016-10-20
  • 打赏
  • 举报
回复
引用 3 楼 zhi_ai_yaya 的回复:
da.Fill(ds, "table"); //把da的查询结果(是一个临时table)填充到ds,在ds里面索引名字是"table"。
那就是把查询结果存到 ds 表集合中的 table 表中? ds集合有这个表吗,如果没有需要怎么在其中建立
我叫小菜菜 2016-10-20
  • 打赏
  • 举报
回复
ds是dataset,数据集,集,即表的集合,可以看做一个内存数据库,可以包含许多张表。 da.Fill(ds, "table"); //把da的查询结果(是一个临时table)填充到ds,在ds里面索引名字是"table"。 dataGridView1.DataSource = ds.Tables["table"];//表格控件绑定数据源为ds的table表。
xiaoqiu_net 2016-10-20
  • 打赏
  • 举报
回复
和你操作SQL Server一样。
我叫小菜菜 2016-10-20
  • 打赏
  • 举报
回复
引用 4 楼 xiaoyuanyuan2009 的回复:
[quote=引用 3 楼 zhi_ai_yaya 的回复:] da.Fill(ds, "table"); //把da的查询结果(是一个临时table)填充到ds,在ds里面索引名字是"table"。
那就是把查询结果存到 ds 表集合中的 table 表中? ds集合有这个表吗,如果没有需要怎么在其中建立[/quote] http://dev.mysql.com/doc/connector-net/en/connector-net-tutorials-data-adapter.html http://www.iteedu.com/database/mysql/mysqlmanualcn/connectors/connector-net-architecture-adapter.php 读取table数据:https://msdn.microsoft.com/zh-cn/library/system.data.dataset.tables

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧