小虾求助,vs2008!

作者在 2011-10-17 10:07:08 发布以下内容
       

一、       实验内容

首先,进入VS2008,新建一个空的网站,网站名可以以本人姓名及学号命名。然后,以下各题分别按下面的操作建立各自的Web窗体:新建/文件/Web窗体,选择C#语言,即新建了一个默认名为default.aspx的网页及default.aspx.cs程序文件,可以右击/重命名,例如第1题可命名为NO1,以此类推。

 

1.      创建一个SQL Server数据库连接,并将连接字符串显示于页面上。

2.      通过connection 对象、command对象,实现对所给定的student表中数据的如下操作:(参考界面如下图所示)

(1)    单击“插入”按钮,将页面上文本框中的内容插入到student表中;

(2)    单击“删除”按钮,根据页面上“学号”文本框中的学号,删除student表中该学号的记录;

(3)    单击“更新”按钮,根据页面上“学号”文本框中的学号,将页面上“姓名”文本框中的内容修改到student表中该学号所对应记录的姓名字段中。

 

3.       通过sqlconnection 对象、sqlcommand对象,当用户从文本框中输入某学生学号, 单击“计算”按钮后,从文本框显示该学生选课门数。

思考:若题目改为:通过sqlconnection 对象、sqlcommand对象,当用户从文本框中输入某学生学号和每门课应缴费金额,单击“计算”按钮后,实现根据该学生的选课门数,计算其应缴纳的费用,结果可用Response对象或用Lable控件、TextBox控件输出。如何处理?

4.      使用SqlCommand对象的ExecuteReader()方法读取多行数据练习。

根据界面上用户从文本框中输入的课程号,查找出选了该课的所有学生学号,当单击“显示”按钮时,在DropDownList控件上显示全部选了该课的学生学号。

 SqlConnection con = new SqlConnection(conStr);
        con.Open();
        string cmdStr = "insert student where Sno='" + this.TextBox1.Text + "'";
        string cmdStr = "insert student where Sname='" + this.TextBox2.Text + "'";
        string cmdStr = "insert student where Ssex='" + this.TextBox3.Text + "'";
        string cmdStr = "insert student where Sage='" + this.TextBox4.Text + "'";
        string cmdStr = "insert student where Sdept='" + this.TextBox5.Text + "'";
        SqlCommand cmd = new SqlCommand(cmdStr, con);
        cmd.ExecuteNonQuery();
        int a = 5;
        string str = "<script>alert('插入成功!" + a.ToString() + "')</script>";
        Response.Write(str);//"<script>alert('插入成功!'+a.)</script>");
        con.Close();

    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        string conStr = "Data Source=JY207-186;Initial Catalog=student;Integrated Security=True";
        SqlConnection con = new SqlConnection(conStr);
        con.Open();
        string cmdStr = "delete student where Sno='" + this.TextBox1.Text + "'";
        SqlCommand cmd = new SqlCommand(cmdStr, con);
        cmd.ExecuteNonQuery();
        int a = 5;
        string str = "<script>alert('删除成功!" + a.ToString() + "')</script>";
        Response.Write(str);//"<script>alert('删除成功!'+a.)</script>");
        con.Close();
    }
    
    protected void Button3_Click1(object sender, EventArgs e)
    {
        string conStr = "Data Source=JY207-186;Initial Catalog=student;Integrated Security=True";
        SqlConnection con = new SqlConnection(conStr);
        con.Open();
        string cmdStr = "updata Sname= '" + this.TextBox2.Text + "'where Sage='" + this.TextBox1.Text + "'";
        SqlCommand cmd = new SqlCommand(cmdStr, con);
        cmd.ExecuteNonQuery();
        int a = 5;
        string str = "<script>alert('更新成功!" + a.ToString() + "')</script>";
        Response.Write(str);//"<script>alert('更新成功!'+a.)</script>");
        con.Close();

    }
    protected void TextBox4_TextChanged(object sender, EventArgs e)
    {

    }
}
 
由于自己水平低,我的代码写成这样,运行代码错误!求高手指点一下!
默认分类 | 阅读 752 次
文章评论,共0条
游客请输入验证码
文章分类
最新评论