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是怎么接收返回结果的!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值