这段代码请问vb.net如何转换为C#,谢谢!急
这段代码请问vb.net如何转换为C#Dim Conn As SqlClient.SqlConnection
Dim cmd As New SqlClient.SqlCommand
Dim Ds As DataSet, SQL As String
Conn = New SqlClient.SqlConnection("data source=(local);initial catalog=DatumManage;user id=sa;pwd=ok")
Conn.Open()
SQL = "Select * From votecount"
Dim Adpt As SqlDataAdapter = New SqlDataAdapter("select * from vote", Conn)
cmd = New SqlClient.SqlCommand(SQL, Conn)
Ds = New DataSet()
Adpt.Fill(Ds, "Vote")
Dim Table1 As DataTable = Ds.Tables("Vote")
Table1.Columns.Add(New DataColumn("得票率", GetType(String)))
Table1.Columns.Add(New DataColumn("直方图", GetType(String)))
Dim I As Integer, Total As Long
For I = 0 To Table1.Rows.Count - 1
Total += Table1.Rows(I).Item("votecount")
Next
Label1.Text="迄今为止,共收到选票 " & Total & " 张。"
If Total = 0 Then Total = 1
For I = 0 To Table1.Rows.Count - 1
Dim Rate = Table1.Rows(I).Item("votecount") / Total
Dim RateHTML As String
Dim RateValue As String
RateHTML = ""
RateValue = FormatNumber(Rate*100, 2) & "%"
Table1.Rows(I).Item("得票率") = RateValue
Table1.Rows(I).Item("直方图") = RateHTML
Next
MyGrid.DataSource = Ds
MyGrid.DataBind()
Conn.Close() --------------------编程问答-------------------- 这点代码自己一句句搞定! --------------------编程问答-------------------- lz根我一样是懒人... --------------------编程问答-------------------- 好像有这种工具,去找一下,上国外开源的网站 --------------------编程问答-------------------- 我试着转了下,有的大小写可能有点问题.
sqlclient.sqlconnection Conn;
SqlClient.SqlCommand cmd = new SqlClient.SqlCommand();
DataSet Ds ;
string SQL;
Conn = New SqlClient.SqlConnection("data source=(local);initial catalog=DatumManage;user id=sa;pwd=ok");
Conn.Open()
Conn.open();
SQL = "Select * From votecount";
SqlDataAdapter Adpt= New SqlDataAdapter("select * from vote", Conn);
cmd = New SqlClient.SqlCommand(SQL, Conn);
Ds = New DataSet();
Adpt.Fill(Ds, "Vote");
DataTable Table1 = Ds.Tables("Vote");
Table1.Columns.Add(New DataColumn("得票率", GetType(String)));
Table1.Columns.Add(New DataColumn("直方图", GetType(String)));
Int32 I ;
Long Total ;
For( I = 0 ; Table1.Rows.Count - 1;I++)
{
Total += Table1.Rows(I).Item("votecount");
}
Label1.Text="迄今为止,共收到选票 " & Total & " 张。";
if (Total = 0 ) Total =1 ;
for(I=0;Table1.Rows.Count-1;I++)
{
Single Rate = Table1.Rows(I).Item("votecount") / Total;
string RateHTML ;
string RateValue ;
RateHTML = "";
RateValue = FormatNumber(Rate*100, 2) & "%";
Table1.Rows(I).Item("得票率") = RateValue;
Table1.Rows(I).Item("直方图") = RateHTML;
}
MyGrid.DataSource = Ds;
MyGrid.DataBind();
Conn.Close(); --------------------编程问答-------------------- SqlConnection Conn;
SqlCommand cmd ;
DataSet Ds;
string SQL;
Conn = new SqlConnection("data source=(local);initial catalog=DatumManage;user id=sa;pwd=ok");
Conn.Open();
SQL = "Select * From votecount";
SqlDataAdapter Adpt = new SqlDataAdapter("select * from vote", Conn);
cmd = new SqlCommand(SQL, Conn);
Ds = new DataSet();
Adpt.Fill(Ds, "Vote");
DataTable Table1 = Ds.Tables["Vote"];
Table1.Columns.Add(new DataColumn("得票率", System.Type.GetType("System.String")));
Table1.Columns.Add(new DataColumn("直方图", System.Type.GetType("System.String")));
long Total;
for( int i = 0 ;i< Table1.Rows.Count ;i++)
{
Total += Convert.ToInt64(Table1.Rows[i]["votecount"].ToString());
}
Label1.Text="迄今为止,共收到选票 " + Total.ToString() + " 张。";
if( Total == 0)
{
Total = 1;
}
for(int i = 0;i< Table1.Rows.Count ;i++)
{
double Rate=Convert.ToInt64(Table1.Rows[i]["votecount"].ToString() )/Total;
string RateHTML="";
string RateValue;
RateValue=FormatNumber(Rate*100, 2) + "%";
Table1.Rows[i]["得票率"] = RateValue;
Table1.Rows[i]["直方图"] = RateHTML;
}
MyGrid.DataSource = Ds;
MyGrid.DataBind();
Conn.Close();
补充:.NET技术 , VB.NET