我想在gridview中显示2个表数据,在SQL中使用类,我正在使用C# [英] I want to show 2 table data in gridview with the use of class in SQL and I am using C#
本文介绍了我想在gridview中显示2个表数据,在SQL中使用类,我正在使用C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在gridview中显示2个表数据,在sql中使用类,我使用c#
我的第一个表名是CreditDebitDetails,第二个是CreditDebitMaster我想在gridview中显示来自两个表格的数据
我尝试过:
i want to show 2 table data in gridview with the use of class in sql and i am using c#
my first table name is CreditDebitDetails and 2nd is CreditDebitMaster i want to show tha data from both table in gridview
What I have tried:
public DataTable credit_gridview()
{
string str2 = "SELECT CreditDebitDetails.date,CreditDebitDetails.chequeno,CreditDebitDetails.chequedate,CreditDebitMaster.totalamount,CreditDebitMaster.narration FROM CreditDebitDetails INNER JOIN CreditDebitMaster ON CreditDebitDetails.CreditDebitmasterid =CreditDebitMaster.CreditDebitmasterid; ";
DataTable dt1 = _objSqlHelper.GetDataTable(str2);
return dt1;
}
推荐答案
由于这是Windows Forms,您绘制 DataGridView类(System.Windows.Forms) [ ^ ],定义 DataGridView.Columns [< a href =https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.columns(v=vs.110).aspx\"target =_ blanktitle =New Window > ^ 你要表现出来。请记住定义 DataGridViewColumn.DataPropertyName属性(System.Windows.Forms) [ ^ ]相应于数据表的列名。
之后你设置了数据表为 DataGridView.DataSource属性(系统.Windows.Forms) [ ^ ]
查看如何:将数据绑定到Windows窗体DataGridView控件 [ ^ ]以及更多信息详细的数据绑定教程 [ ^ ]
Since this is Windows Forms, you draw the DataGridView Class (System.Windows.Forms)[^] , define the DataGridView.Columns[^] you want to show. Just remember to define the DataGridViewColumn.DataPropertyName Property (System.Windows.Forms)[^] accordingly to the column name of the datatable.
After that you set the the datatable as DataGridView.DataSource Property (System.Windows.Forms)[^]
Have a look at How to: Bind Data to the Windows Forms DataGridView Control[^] and for more information A Detailed Data Binding Tutorial[^]
这篇关于我想在gridview中显示2个表数据,在SQL中使用类,我正在使用C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文