using System.Collections.Generic;
using System.Linq;
Using System. The Web;
Using System. Web. UI.
Using System. Web. UI. WebControls;
using System.Data;
Using System. The Configuration;
Using System. Web. Security;
Using System. Web. UI. WebControls. WebParts;
Using System. Web. UI. HtmlControls;
using System.Data.SqlClient;
Using System. The Collections;
Using System. Xml. Linq.
The namespace attendance management system
{
Public partial class serve: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{
}
Protected void Button1_Click (object sender, EventArgs e)
{
String STR="Server=. The Database=WAMS; User id=sa; The PWD=123456 ";
SqlConnection conn=new SqlConnection (STR);
conn.Open();
String SQL="select stu_num as students' student id ', teacher_num as' teacher number, course_num as' courses' course_time as' class time, stu_status as' attendance status from work_record where course_num='" + TextBox2. Text +"' and course_time='" + TextBox3. Text + "' and teacher_num='" + TextBox1. Text + "' ";
SqlCommand CMD=new SqlCommand (SQL, conn);
SqlDataReader Dr=CMD. ExecuteReader ();
GridView1. The DataSource=Dr;
GridView1. DataBind ();
Dr. Close ();
Conn. Close ();
}
Private void the Bind ()
{
String STR="Server=. The Database=WAMS; User id=sa; The PWD=123456 ";
SqlConnection conn=new SqlConnection (STR);
conn.Open();
String SQL="select stu_num as students' student id ', teacher_num as' teacher number, course_num as' courses' course_time as' class time, stu_status as' attendance status from work_record where course_num='" + TextBox2. Text +"' and course_time='" + TextBox3. Text + "' and teacher_num='" + TextBox1. Text + "' ";
SqlCommand CMD=new SqlCommand (SQL, conn);
SqlDataReader Dr=CMD. ExecuteReader ();
GridView1. The DataSource=Dr;
GridView1. DataBind ();
Dr. Close ();
Conn. The Dispose ();
}
Protected void GridView1_RowEditing (object sender, GridViewEditEventArgs e)
{
GridView1. EditIndex=e.N ewEditIndex;
The Bind ();
}
Protected void GridView1_Rowupdating (object sender, GridViewUpdateEventArgs e)
{
GridViewRow row=GridView1. Rows [" e.R owIndex];
String stu_num=row. Cells [1]. The Text;
String teacher_num=row. Cells [2]. The Text;
String course_num=row. Cells [3]. The Text;
String course_time=row. Cells [4]. The Text;
String stu_status=((TextBox) row Cells. [5] Controls [0]). The Text;
Updategridview (stu_num teacher_num, course_num course_time, stu_status);
}
Private void updategridview (string stu_num, string teacher_num, string course_num, string course_time, string stu_status)
{
String SQL=@ "update work_record set stu_status=@ stu_status
Where stu_num=@ stu_num and teacher_num=@ teacher_num and course_num=@ course_num and course_time=@ course_time ";
String STR="Server=. The Database=WAMS; User id=sa; The PWD=123456 ";
SqlConnection conn=new SqlConnection (STR);
conn.Open();
SqlCommand CMD=new SqlCommand (SQL, conn);
CMD. The Parameters. AddWithValue (" @ stu_num, "stu_num);
CMD. The Parameters. AddWithValue (" @ teacher_num, "teacher_num);
CMD. The Parameters. AddWithValue (" @ course_num "course_num);
CMD. The Parameters. AddWithValue (" @ course_time, "course_time);
CMD. The Parameters. AddWithValue (" @ stu_status, "stu_status);
CMD. ExecuteNonQuery ();
Cmd.Com mandText=@ "select stu_num as students' student id ', teacher_num as' teacher number, course_num as' courses' course_time as' class time, stu_status as' attendance status from work_record where course_num='" + TextBox2. Text +"' and course_time='" + TextBox3. Text + "' and teacher_num='" + TextBox1. Text + "' ";
CMD. The Parameters. The Clear ();
SqlDataReader Dr=CMD. ExecuteReader ();
GridView1. The DataSource=Dr;
GridView1. EditIndex=1;
GridView1. DataBind ();
Dr. Close ();
CMD. The Dispose ();
}
Protected void GridView11_RowCancelingEdit (object sender, GridViewCancelEditEventArgs e)
{
GridView1. EditIndex=1;
The Bind ();
}
}
}
CodePudding user response:
Your code is not an error? Update to update multiple fields use commas, not the and connectedCodePudding user response:
Debugging and see int n=CMD. ExecuteNonQuery (); N after execution is how much, if 0 is your condition is not correct, such as the time is formatted, matching,Don't your table setting key? With so many conditions to determine the update line?
Besides, you can the GridView is inherently Settings automatically updated after the update statement in the data source, don't have to write their own background,