谁能帮我把这VB.net的代码转成C#,谢谢!

aganzi1111 2007-01-24 10:34:24
<Script Language="vb" Runat="Server">
sub Page_Load(Sender As Object,E As Eventargs)
Lb1.InnerHtml = now.date
BindGrid()
end sub

Sub Selected_Click(Sender As Object,E As Eventargs)
Lb1.InnerHtml = Calendar1.SelectedDate.ToShortDateString
BindGrid()
End Sub

Sub BindGrid()
Dim StrCnn As String
Dim Cnn As OleDbConnection
Dim dtcmd As OleDbDataAdapter
Dim dt As New DataTable
Dim Str1 As String
Dim remind_date As String
remind_date = Calendar1.SelectedDate.ToShortDateString
if Calendar1.SelectedDate.ToShortDateString = "0001-1-1" then
remind_date = now.date
end if
Str1 = "select * from art_info where addtime=#"&cdate(remind_date)&"# order by id desc"
StrCnn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("data.mdb")
Cnn = New OleDbConnection(StrCnn)
Cnn.Open()
dtcmd = New OleDbDataAdapter(Str1, Cnn)
dtcmd.Fill(dt)
DataGrid1.DataSource = dt
DataGrid1.DataBind()
Cnn.Close()
End Sub
</Script>
...全文
226 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
kissknife 2007-01-24
  • 打赏
  • 举报
回复
try..
if (Calendar1.SelectedDate.ToShortDateString() == "0001-1-1")
{
remind_date = DateTime.Now.ToShortDateString();
}
yoursunboy 2007-01-24
  • 打赏
  • 举报
回复
c#里面是:
DateTime.now()

==================================
小小姑娘
清早起床
提着裤子上茅房
茅房有人,不能再等
只好拉在裤子上..................
==================================
王集鹄 2007-01-24
  • 打赏
  • 举报
回复
private void button1_Click(object sender, EventArgs e)
{
DateTime vDateTime = DateTime.Now;
Text = vDateTime.ToString();
}
aganzi1111 2007-01-24
  • 打赏
  • 举报
回复
这个now.date在C#中也不能使用!
或者我不知道怎么用.
取得当前时间的.用这个取不来
yoursunboy 2007-01-24
  • 打赏
  • 举报
回复
回复楼上,这么写:
if (Calendar1.SelectedDate.ToShortDateString == "0001-1-1")
{
remind_date = now.date;
}

==================================
小小姑娘
清早起床
提着裤子上茅房
茅房有人,不能再等
只好拉在裤子上..................
==================================
aganzi1111 2007-01-24
  • 打赏
  • 举报
回复
if Calendar1.SelectedDate.ToShortDateString = "0001-1-1" then
remind_date = now.date
end if
其他我都换好了,就这里会出错!
帮忙换一下,我刚学不久做做参考嘛
yn098 2007-01-24
  • 打赏
  • 举报
回复
http://www.developerfusion.co.uk/utilities/convertvbtocsharp.aspx
yoursunboy 2007-01-24
  • 打赏
  • 举报
回复
太简单了,不过没时间帮
只好帮定

==================================
小小姑娘
清早起床
提着裤子上茅房
茅房有人,不能再等
只好拉在裤子上..................
==================================
lr21shiji 2007-01-24
  • 打赏
  • 举报
回复
自己搞吧 vb.net 语法 和c# 语法相差不大
aganzi1111 2007-01-24
  • 打赏
  • 举报
回复
VB.NET的那代码是我同事写的.我不太熟悉!
他用ACCESS做了这个功能,我用C#+SQL改掉.
他比我强!
viena 2007-01-24
  • 打赏
  • 举报
回复
& 是VB的字符串连接符,C#中用+
viena 2007-01-24
  • 打赏
  • 举报
回复
没注意看,其实转为DateTime是画蛇添足了
直接连接字符串即可
& cdate(remind_date) &
改为
+ remind_date +

另外你最前面不是Access,用OleDb的吗?
怎么改SqlServer了?
如果是SqlServer,#应换为'
aganzi1111 2007-01-24
  • 打赏
  • 举报
回复
viena的建议我按照改了一下,出错
SqlDataAdapter myCommand=new SqlDataAdapter("where addtime=#"&DateTime.Parse(remind_date)&"# order by id desc",myConnection);

运算符“&”无法应用于“string”和“System.DateTime”类型的操作数!
这样取得不行的!
高手们,快点进来啊!
viena 2007-01-24
  • 打赏
  • 举报
回复
cdate是VB的函数

cdate(remind_date)

=>

DateTime.Parse(remind_date)
aganzi1111 2007-01-24
  • 打赏
  • 举报
回复
转化过后代码为:
private void Page_Load(object sender, System.EventArgs e)
{

rqi.Text=System.DateTime.Now.ToString("yyyy-MM-dd");;
BindData();

}

#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void Selected_Click(object sender, System.EventArgs e)
{
rqi.Text = Calendar1.SelectedDate.ToShortDateString();
BindData();
}

protected void BindData()
{


String remind_date;

remind_date = Calendar1.SelectedDate.ToShortDateString();

if (Calendar1.SelectedDate.ToShortDateString() == "0001-1-1")
{
remind_date = DateTime.Now.ToShortDateString();
}


SqlConnection myConnection=new SqlConnection("server=KC-AGANZI;uid=sa;pwd=123456;database=CCE;");
SqlDataAdapter myCommand=new SqlDataAdapter("where addtime=#"&cdate(remind_date)&"# order by id desc",myConnection);
DataSet ds=new DataSet();
myCommand.Fill(ds,"KC_tixingshiwu");
DataGrid1.DataSource=ds.Tables["KC_tixingshiwu"].DefaultView;
DataGrid1.DataBind();
myConnection.Close();

}
这个cdate是什么意思?

110,545

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧