文章目录
1.选课部分的代码
代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
public partial class Default3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string ~serial_no = GridView1.DataKeys[e.RowIndex].Value.ToString();
string ~student_id = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString();
string ~course_id = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString();
string ~course_name = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString();
string sqlStr = "update ~course_select set student_id='" + student_id + "',course_id=" + course_id + " , course_name ='" + course_name + "', select_time = Getdate() where serial_no= " + serial_no;
String str = "Server=【~命令提示符IP:config10.0.121.34】,1433;User Id=sa;Pwd=123;DataBase=【学生】";
SqlConnection conn = new SqlConnection(str);
conn.Open();
SqlCommand cmd = new SqlCommand(sqlStr, conn);
SqlDataSource1.UpdateCommand = sqlStr;
int num = cmd.ExecuteNonQuery();
cmd.Dispose();
conn.Close();
GridView1.EditIndex = -1;
GridView1.DataBind();
}
}