如何使用datagridview绑定c#数据表 [英] How To Bind c# Data table With datagridview

查看:64
本文介绍了如何使用datagridview绑定c#数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在c#windows应用程序中创建了一个数据表

我在这个datagridview中添加了两列(colItemCode,colDescription)



现在我想绑定这个datagrideview与sql数据表调用ITEM_MASTER



特别的是我要添加表提交(itCode,itDescription,这些都是SQL表字段)在windows窗体应用程序的datagridview中调用两列(colItemCode,colDescription)



如何执行此操作

thak you

解决方案

您好,



这里有一些符合您要求的链接。



1. http://www.dotnetperls.com/datatable [ ^ ]



2. http://stackover flow.com/questions/1042618/how-to-create-a-datatable-in-c-sharp-and-how-to-add-rows [ ^ ]



3. 如何在datagridview中编辑和保存?在c#.net windows应用程序中 [ ^ ]


你好,

类似要求我面对几个月回来。所以我成就了帮助Pf以下步骤

1)首先从数据库中解析表格。

2)将列添加到数据表中

3)绑定数据表到GRid视图。



将列添加到数据表中

假设:您已将DataTable对象声明为dt

 dt.Columns.Add(  colItemCode); 
dt.Columns.Add( colDescription);





此后绑定GridView

 dataGridView1。 DataSource = dt 





它将显示添加的表中添加的列

[如果插入一些数据到dt,然后写dt.AcceptChanges();]



希望它解决你的问题

快乐编码

: - )


 dataGridView1.DataSource = ITEM_MASTER; 
dataGridView1.Columns [ 0 ]。DataPropertyName = itCode;
dataGridView1.Columns [ 1 ]。DataPropertyName = itDescription;


I have created a data table in c# windows application
and i have add two columns to this datagridview (colItemCode,colDescription)

now i want to bind this datagrideview with sql data table call ITEM_MASTER

Special thing is i want to add the table filed (itCode,itDescription, these are SQL table field) To two columns call (colItemCode,colDescription) in datagridview in windows form application

how to do this
thak you

解决方案

Hi,

Here are some links to meeting your requirements.

1. http://www.dotnetperls.com/datatable[^]

2.http://stackoverflow.com/questions/1042618/how-to-create-a-datatable-in-c-sharp-and-how-to-add-rows[^]

3.how to edit and save in datagridview? in c# .net windows application[^]


Hello ,
Similar Requirement I Faced Some Months Back.So i Achieved with The Help Pf Following Steps
1) First Retieve The Table From DataBase.
2) Add The Column into That DataTable
3) Bind The Datatable To The GRid View.

To Add The Columns into The Data Table
Assumption: you have declared a DataTable Object as dt

dt.Columns.Add("colItemCode");
dt.Columns.Add("colDescription");



After this Bind The GridView

dataGridView1.DataSource = dt



It will display the columns added in the added table
[If you insert some data into dt,then write dt.AcceptChanges();]

Hope It Solves Your Problem
Happy Coding
:-)


dataGridView1.DataSource = ITEM_MASTER;
dataGridView1.Columns[0].DataPropertyName = "itCode";
dataGridView1.Columns[1].DataPropertyName = "itDescription";


这篇关于如何使用datagridview绑定c#数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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