不从mysqlserver读取数据 [英] Not reading data from mysqlserver

查看:64
本文介绍了不从mysqlserver读取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在gridview中显示我的表格。但它没有取得数据。任何人都可以为我检查代码

I am trying to display my table in gridview. But its not fetching the data. Can any one check the code for me

MySqlConnection cn = new MySqlConnection(@"server=localhost;User Id=dksolution;password=*******;Persist Security Info=True;port=3307;database=aiil");
            MySqlCommand cmd = new MySqlCommand("select * from user_details",cn);
            cn.Open();
            MySqlDataReader rd = cmd.ExecuteReader();
            GridView1.DataSource = rd;
           
            GridView1.DataBind();
            cn.Clone();

推荐答案

检查下面提到的链接,它对你有帮助。



连接到使用C#和.NET的MySQL数据库 [ ^ ]



如何使用C#连接MySQL [ ^ ]



我希望这会有所帮助你。
Check below mentioned links where it'll help to you.

Connecting to MySQL Database using C# and .NET[^]

How to Connect to MySQL Using C#[^]

I hope this will help to you.


引用:

但它没有取数据



我将假设你的不取的证据不仅仅是因为它不在您的GridView中显示...



首先查看您的连接字符串。在调试器中逐步执行代码,并在打开后检查 cn 的内容。



如果可以的话然后查看 rd 的内容,以确认您实际上已经获取了一些数据。



如果没有,那么检查你的表和数据库名称的拼写/大写字母(我假设你已经检查过该表中有数据)



如果您的记录集中有数据,那么它就是您绑定到GridView的方式 - 我认为您应该在某处填充数据集...看看这个示例 [ ^ ]


I'm going to assume that your evidence of "not fetching" isn't just because it's not displaying in your GridView...

Look to your connection string first. Step through your code in the debugger and check the contents of cn after the Open.

If that is ok then have a look at the contents of rd to confirm that you have actually fetched some data.

If not then check for spelling/capitals on your table and database names (I'm assuming you've already checked that there is data in that table)

If there is data in your recordset then it's the way you are binding to the GridView - I think you should be filling a dataset in there somewhere ... have a look at this example[^]


这篇关于不从mysqlserver读取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆