我在这个gridview 的每一行都有一个gridview 和linkbuttons。当我单击其中一个按钮时,我会得到该行的 courseName、courseCode 和术语列值的值。这是我的代码:
int row = -1;
int.TryParse(e.CommandArgument as string, out row);
GridViewRow gdrow = instCourses.Rows[row];
// *** Get the underlying data item - in this case a DataRow
DataRow dr = ((DataTable)this.instCourses.DataSource).Rows[gdrow.DataItemIndex];
// *** Retrieve our context
string courseCode = dr["CourseCode"].ToString();
string courseNumber = dr["CourseNumber"].ToString();
string term = dr["Term"].ToString();
SqlConnection con = new SqlConnection();
con.ConnectionString = Userfunctions.GetConnectionString();
con.Open();
SqlCommand cmd=new SqlCommand("select RegisterTable.StudentID,StudentTable.Name,StudentTable.Surname from RegisterTable INNER JOIN StudentTable where RegisterTable.StudentID=StudentTable.StudentID and RegisterTable.CourseCode=@courseCode and RegisterTable.Term=@term and RegisterTable.CourseNumber=@courseNumber",con);
cmd.Parameters.AddWithValue("@courseCode", courseCode);
cmd.Parameters.AddWithValue("@courseNumber", courseNumber);
cmd.Parameters.AddWithValue("@term", term);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
studList.DataSource = dt;
studList.DataBind();
这些值按我的预期返回,但我认为我的查询有问题,它在关键字“where”附近显示语法不正确。任何人都可以看到问题吗?
谢谢