1、 DataSet ds=new DataSet () ; SqlDataAdapter da = new SqlDataAdapter(select * from users where userid= + txtid.Text + and userpwd= + txtpassword.Text + , conn); da.Fill(ds); if (ds.Tables0.Rows.Count=0) Label3 .Text =账号或密码错误,请重新输入! else Session userid=txtid .Text ; Sessionuserpwd = txtpassword.Text;u
2、sername = ds.Tables0.Rows0.ToString();userpower if (Session.ToString () = 0) Response.Redirect(admin/index.aspx); else if (Session.ToString() = 1student/index.aspx Label3.Text = 对不起,权限验证失败 conn.Close(); ds.Clear ();二、添加课程页面代码 SqlCommand mycmd; SqlConnection conn; protected void Page_Load(object send
3、er, EventArgs e) conn = new SqlConnection(strconn); Label7.Text = 课程号不能为空 string sqlstr = sqlstr = insert into course(courseid,coursename,coursetime,fen,type,teacher)values( + courseid.Text + , + coursename.Text + + coursetime.Text + + fen.Text + + type.Text + + teacher.Text + ) mycmd = new SqlComma
4、nd(sqlstr, conn); mycmd.Dispose(); try mycmd.ExecuteNonQuery(); Response.Write(javascript:alert(添加成功!/script catch (SqlException)添加失败! finally protected void Button2_Click(object sender, EventArgs e) courseid.Text = coursename.Text = coursetime.Text = fen.Text = type.Text = protected void Button3_Cl
5、ick(object sender, EventArgs e)course.aspx三、添加成绩程序代码 if (userid.SelectedValue .ToString ()= Label11.Text = 学号不能为空insert into score(userid,username,courseid,coursename,score,year)values( + userid.SelectedValue + + username.Text + + txtcourseid.SelectedValue + + score.Text + + txtyear.SelectedValue +
6、username.Text = score.Text = txtyear.Text = score.aspx protected void userid_SelectedIndexChanged(object sender, EventArgs e)select username from students where userid= SqlDataReader da; da = mycmd.ExecuteReader(); while (da.Read() username.Text = da protected void txtcourseid_SelectedIndexChanged(o
7、bject sender, EventArgs e)select coursename from course where courseid= coursename.Text = dacoursename四、添加学生程序代码using System.IO;using System.Text; return; string sql = 获取上传文件的名称 string type = name.Substring(name.LastIndexOf() + 1);/获取上传文件的后缀 string query1 = insert into images(userid,path) values( +
8、userid.Text + ,path) FileUpload1.SaveAs(ipath); /服务器保存路径 SqlCommand cm = new SqlCommand(query1); cm.Connection = conn; cm.Parameterspath.Value = wpath; cm.ExecuteNonQuery(); / this.lb_info.Text = 上传成功! string sqlstr1 = sqlstr1 = insert into users(userid,username)values( + txtusername.Text + ) SqlCom
9、mand mycmd1 = new SqlCommand(sqlstr1, conn); mycmd1.Dispose(); mycmd1.ExecuteNonQuery(); userid.Text = txtusername.Text = txtminzu.Text = txtbirthday.Text = txtclass.Text = txtcomefrom.Text = txtbeizhu.Text = student.aspx五、检查课程号唯一性程序代码 Response.Expires = 0; string nam = Request.QueryStringnameselect
10、 courseid from course where courseid= + nam + SqlCommand DBHelper; DBHelper = new SqlCommand(sql, conn); SqlDataReader dr = DBHelper.ExecuteReader(); if (dr.Read()b class=Error该课程号已经存在,请换一个 Right该课程号可以使用 dr.Close(); 六、检查学号唯一性程序代码select userid from students where userid=该学号已经存在,请换一个该学号可以使用七、课程信息程序代码
11、SqlDataReader getdata; DataSet ds = new DataSet(); sql = select * from course order by courseid mycmd = new SqlCommand(sql, conn); getdata = mycmd.ExecuteReader(); grdMain.DataSource = getdata; grdMain.DataBind(); DataSet ds; string strsql = SqlCommand cmd; strsql = select * from course where course
12、id=or coursename like cmd = new SqlCommand(strsql, conn); da = cmd.ExecuteReader(); Datagrid1.DataSource = da; Datagrid1.DataBind(); cmd.Dispose();八、编辑、删除学生信息程序代码 SqlCommand cmd2; if (!this.IsPostBack) SqlDataReader reader; string uid = uid = Page.Requestidselect * from students where userid= + uid + cmd = new SqlCommand(sql, conn); reader = cmd.ExecuteReader(); while (reader.Read() userid.Text = readeruserId txtusername.Text = readerus
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1