本文介绍了在Windows Apps中通过MySqlDataReader对象填充GridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

开发Windows应用程序。并且需要代码来填充DataView的GridView(有4列)。

我的代码是: -



string strSearch2 =Select * From supplier_contacts supplier_code =''+ txtSearch.Text +''';

MySqlCommand cmdSearch2 = new MySqlCommand(strSearch2,con);

MySqlDataReader drSearch2 = cmdSearch2.ExecuteReader ();

if(drSearch2.HasRows)

{

while(drSearch2.Read())

{

GVcontacts.DataSource = drSearch2;



}

}

Developing a windows apps. and need code to populate GridView(Having 4 columns) by DataReader.
my code is :-

string strSearch2 = "Select * From supplier_contacts where supplier_code=''" + txtSearch.Text + "''";
MySqlCommand cmdSearch2 = new MySqlCommand(strSearch2, con);
MySqlDataReader drSearch2 = cmdSearch2.ExecuteReader();
if (drSearch2.HasRows)
{
while(drSearch2.Read())
{
GVcontacts.DataSource = drSearch2;

}
}

推荐答案

string strSearch2 = "SELECT * FROM supplier_contacts WHERE supplier_code = '" + txtSearch.Text + "'";
MySqlCommand cmdSearch2 = new MySqlCommand(strSearch2, con);
MySqlDataReader drSearch2 = cmdSearch2.ExecuteReader();
GVcontacts.DataSource = drSearch2;



问候,


Regards,


这篇关于在Windows Apps中通过MySqlDataReader对象填充GridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 19:20