如何将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 展开
' 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 展开
2个回答
展开全部
转换好了,自己比较,也没什么就是定义类、定义变量之类的东西该变一下写法
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;
}
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;
}
展开全部
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 ;
}
}
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 ;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询