| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 631 人关注过本帖
标题:ASP.NET(VB)如何转成ASP.NET(C#)
只看楼主 加入收藏
lin9576
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2011-12-23
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
ASP.NET(VB)如何转成ASP.NET(C#)
请问怎么把下面VB的for语句改成C#的,谢谢~~~~~~~~~~
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim intClassID As Integer = Convert.ToInt32(ddlstclass.SelectedItem.Value)
        Dim intCourseID As Integer = Convert.ToInt32(ddlstcourse.SelectedItem.Value)
        Dim intTeacherID As Integer = Convert.ToInt32(ddlstTea.SelectedItem.Value)
        Dim intTerm As String = TextBox1.Text
        Dim conn As New SqlConnection
        conn.ConnectionString = ConfigurationManager.ConnectionStrings("ASPNETDBConnectionString").ConnectionString
        Dim i As Integer
        For i = 0 To gvstu.Rows.Count - 1
            Dim lbl1 As Label
            lbl1 = gvstu.Rows.Item(i).FindControl("Label1")
            Dim intStudentID As Integer = Convert.ToInt32(lbl1.Text)
            intStudentID = Convert.ToInt32(lbl1.Text)
            Dim strsql As String = "insert into Score(studenID,courseID,TeacherID,Term) values(" & intStudentID & "," & intCourseID & "," & intTeacherID & ",'" & intTerm & "')"
            Dim cmd As New SqlCommand(strsql, conn)
            conn.Open()
            cmd.ExecuteNonQuery()
            conn.Close()
        Next
    End Sub
搜索更多相关主题的帖子: Object 如何 
2012-01-18 16:38
xydddaxia
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:33
帖 子:466
专家分:2307
注 册:2009-3-20
收藏
得分:20 
程序代码:
  Protected void button1_Click(object sender, EventArgs e)
        {
            int intClassID = int.Parse(ddlstclass.SelectedItem.Value);
            int intCourseID = int.Parse(ddlstcourse.SelectedItem.Value);
            int intTeacherID = int.Parse(ddlstTea.SelectedItem.Value);
            string intTerm = TextBox1.Text;
            System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection();
            conn.ConnectionString = ConfigurationManager.ConnectionStrings("ASPNETDBConnectionString").ConnectionString;
            for (int i = 0; i < gvstu.Rows.Count - 1; i++)
            {
                Label lbl1 = gvstu.Rows.Item[i].FindControl("Label1");
                int intStudentID = int.Parse(lbl1.Text);
                intStudentID = int.Parse(lbl1.Text);
                string strsql = "insert into Score(studenID,courseID,TeacherID,Term) values(" + intStudentID + "," + intCourseID + "," + intTeacherID + ",'" + intTerm + "')";
                System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(strsql, conn);
                conn.Open();
                cmd.ExecuteNonQuery();
                conn.Close();
            }
        }


[ 本帖最后由 xydddaxia 于 2012-1-30 09:10 编辑 ]

站在春哥的肩膀上
2012-01-18 17:41
快速回复:ASP.NET(VB)如何转成ASP.NET(C#)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019478 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved