如何使用datatable类创建表 [英] How to create table with datatable class

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

问题描述

嗨朋友

我想用Datatable class.i创建一个表使用此代码:





Hi friends
I wanted to create a table with Datatable class.i used this code:


DataTable dt = new DataTable("tbl1");
            DataColumn column1 = new System.Data.DataColumn();
            column1.ColumnName = "First";
            column1.DataType = typeof(int);
            column1.DefaultValue = 0;
            column1.Unique = true;
            column1.AllowDBNull = false;
            dt.Columns.Add();
            DataSet se= new System.Data.DataSet();
            se.Tables.Add(dt);





但它不起作用。

如何使用Datatable类在数据库中创建表?是否可以?



请指导我!

谢谢



我尝试过:



............................................... ..................



But It doesn't work.
How can i create table in database with Datatable class?is it possible?

please guide me!
thanks

What I have tried:

.................................................................

推荐答案

你的代码有效:它没有做太多!

具体来说,它不会显示任何内容,因此您可以看到它已经工作。

使用DataTabe作为数据感知控件(如DatGirdView或类似数据)的DataSource ,你会看到。



如果你添加一些数据它会更好!

Your code works: it just doesn't do much!
Specifically, it doesn't display anything, so you can;t see that it has worked.
Use the DataTabe as the DataSource for a data aware control such as a DatGirdView or similar, and you'll see.

And it'd work better if you added some data!
column1.AllowDBNull = false;
dt.Columns.Add();
dt.Rows.Add(111);
dt.Rows.Add(112);
dt.Rows.Add(113);
DataSet se = new System.Data.DataSet();
se.Tables.Add(dt);
myDataGridView.DataSource = dt;


这篇关于如何使用datatable类创建表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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