如何将VB转为C#代码 20

FunctionGetData()AsDataTable'ThismethodcreatesaDataTablewithfourrows.Eachrowhasthe'fo... Function GetData() As DataTable
' This method creates a DataTable with four rows. Each row has the
' following schema:
' PictureID int
' PictureURL string
' Title string
' DateAdded datetime

Dim dt As New DataTable()

' define the table's schema
dt.Columns.Add(New DataColumn("PictureID", GetType(Integer)))
dt.Columns.Add(New DataColumn("PictureURL", GetType(String)))
dt.Columns.Add(New DataColumn("Title", GetType(String)))
dt.Columns.Add(New DataColumn("DateAdded", GetType(DateTime)))

' Create the four records
Dim dr As DataRow = dt.NewRow()
dr("PictureID") = 1
dr("PictureURL") = ResolveUrl("Images/Blue hills.jpg")
dr("Title") = "Blue Hills"
dr("DateAdded") = New DateTime(2005, 1, 15)
dt.Rows.Add(dr)

dr = dt.NewRow()
dr("PictureID") = 2
dr("PictureURL") = ResolveUrl("../DisplayingImages/Images/Sunset.jpg")
dr("Title") = "Sunset"
dr("DateAdded") = New DateTime(2005, 1, 21)
dt.Rows.Add(dr)

dr = dt.NewRow()
dr("PictureID") = 3
dr("PictureURL") = ResolveUrl("\DisplayingImages\ImageAsURL\Blue hills.jpg")
dr("Title") = "Water Lilies"
dr("DateAdded") = New DateTime(2005, 2, 1)
dt.Rows.Add(dr)

dr = dt.NewRow()
dr("PictureID") = 4
dr("PictureURL") = ResolveUrl("/DisplayingImages/Images/Winter.jpg")
dr("Title") = "Winter"
dr("DateAdded") = New DateTime(2005, 2, 18)
dt.Rows.Add(dr)

Return dt
End Function
展开
 我来答
蓝域zG
2007-01-20 · TA获得超过4534个赞
知道大有可为答主
回答量:2257
采纳率:0%
帮助的人:1017万
展开全部
转换好了,自己比较,也没什么就是定义类、定义变量之类的东西该变一下写法

DataTable GetData()
{
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("PictureID", typeof(int)));
dt.Columns.Add(new DataColumn("PictureURL", typeof(string)));
dt.Columns.Add(new DataColumn("Title", typeof(string)));
dt.Columns.Add(new DataColumn("DateAdded", typeof(DateTime)));
DataRow dr = dt.NewRow();
dr("PictureID") = 1;
dr("PictureURL") = ResolveUrl("Images/Blue hills.jpg");
dr("Title") = "Blue Hills";
dr("DateAdded") = new DateTime(2005, 1, 15);
dt.Rows.Add(dr);
dr = dt.NewRow();
dr("PictureID") = 2;
dr("PictureURL") = ResolveUrl("../DisplayingImages/Images/Sunset.jpg");
dr("Title") = "Sunset";
dr("DateAdded") = new DateTime(2005, 1, 21);
dt.Rows.Add(dr);
dr = dt.NewRow();
dr("PictureID") = 3;
dr("PictureURL") = ResolveUrl("\\DisplayingImages\\ImageAsURL\\Blue hills.jpg");
dr("Title") = "Water Lilies";
dr("DateAdded") = new DateTime(2005, 2, 1);
dt.Rows.Add(dr);
dr = dt.NewRow();
dr("PictureID") = 4;
dr("PictureURL") = ResolveUrl("/DisplayingImages/Images/Winter.jpg");
dr("Title") = "Winter";
dr("DateAdded") = new DateTime(2005, 2, 18);
dt.Rows.Add(dr);
return dt;
}
lxcwh09
2007-01-21 · TA获得超过1267个赞
知道小有建树答主
回答量:1667
采纳率:0%
帮助的人:1232万
展开全部
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
DataTable GetData()
{
//This method creates a DataTable with four rows. Each row has the
// following schema:
// PictureID int
//' PictureURL string
//' Title string
//' DateAdded datetime

DataTable dt= new DataTable();

//' define the table's schema
dt.Columns.Add(new DataColumn("PictureID", GetType(Integer)));
dt.Columns.Add(new DataColumn("PictureURL", GetType(String))) ;
dt.Columns.Add(new DataColumn("Title", GetType(String)));
dt.Columns.Add(new DataColumn("DateAdded", GetType(DateTime))) ;

//Create the four records
DataRow dr = dt.newRow() ;
dr("PictureID") = 1 ;
dr("PictureURL") = ResolveUrl("Images/Blue hills.jpg") ;
dr("Title") = "Blue Hills" ;
dr("DateAdded") = new DateTime(2005, 1, 15);
dt.Rows.Add(dr);

dr = dt.newRow();
dr("PictureID") = 2;
dr("PictureURL") = ResolveUrl("../DisplayingImages/Images/Sunset.jpg") ;
dr("Title") = "Sunset";
dr("DateAdded") = new DateTime(2005, 1, 21) ;
dt.Rows.Add(dr) ;

dr = dt.newRow() ;
dr("PictureID") = 3 ;
dr("PictureURL") = ResolveUrl("\DisplayingImages\ImageAsURL\Blue hills.jpg") ;
dr("Title") = "Water Lilies" ;
dr("DateAdded") = new DateTime(2005, 2, 1) ;
dt.Rows.Add(dr) ;

dr = dt.newRow() ;
dr("PictureID") = 4 ;
dr("PictureURL") = ResolveUrl("/DisplayingImages/Images/Winter.jpg") ;
dr("Title") = "Winter" ;
dr("DateAdded") = new DateTime(2005, 2, 18) ;
dt.Rows.Add(dr) ;

Return dt ;
}

}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式