在C#2008中使用System.Data.DataTable在Visual Basic 2008 VS中导入System.Data.DataTable [英] Import System.Data.DataTable in Visual Basic 2008 VS Using System.Data.DataTable in C# 2008
本文介绍了在C#2008中使用System.Data.DataTable在Visual Basic 2008 VS中导入System.Data.DataTable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在VB.Net中,可以将名为
In VB.Net a package called
System.Data.DataTable
的包导入工作表单或类。但我尝试使用C#,如
can be imported to a working form or to a class. But I tried this by doing C# like
Using System.Data.DataTable
给我一个错误,说使用命名空间指令只能应用于名称空间;'' System.Data.DataTable是一个类型而不是命名空间''。
然后我如何在C#2008中使用DataTable?
如果你们有时间,请帮助我。
谢谢!
Chiransj
gives me an error, saying "A using a namespace directive can only be applied to namespaces;''System.Data.DataTable is a type not a namespace''.
Then how am I able to use DataTable in C# 2008 ?
Please help me if you guys have some time.
Thank You!
Chiransj
推荐答案
替换为
Replace it with
using System.Data;
并且DataTable类将是可用的:
And the DataTable class will be avaialble:
DataTable dt = new DataTable();
你不能使用使用
的类,它基本上只定义了一个''快捷方式''到VB中的命名空间,如import
。
而是定义一个包含实例的变量班级和分配它是一个实例。
来自 MSDN [ ^ ] :
You cannot use a class withusing
which basically defines just a ''shortcut'' to a namespace, likeimports
in VB.
Instead you define a variable which holds an instance of the class and assign an instance to it.
An example from MSDN[^]:
private void MakeDataTableAndDisplay()
{
// Create new DataTable.
DataTable table = new DataTable();
// Declare DataColumn and DataRow variables.
DataColumn column;
DataRow row;
// Create new DataColumn, set DataType, ColumnName
// and add to DataTable.
column = new DataColumn();
column.DataType = System.Type.GetType("System.Int32");
column.ColumnName = "id";
table.Columns.Add(column);
// Create second column.
column = new DataColumn();
column.DataType = Type.GetType("System.String");
column.ColumnName = "item";
table.Columns.Add(column);
// Create new DataRow objects and add to DataTable.
for(int i = 0; i < 10; i++)
{
row = table.NewRow();
row["id"] = i;
row["item"] = "item " + i;
table.Rows.Add(row);
}
// Set to DataGrid.DataSource property to the table.
dataGrid1.DataSource = table;
}
这篇关于在C#2008中使用System.Data.DataTable在Visual Basic 2008 VS中导入System.Data.DataTable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文