I have a gridview and linkbuttons at every row of this gridview. When i click one of the buttons, i get the values of the courseName,courseCode and term column values of this row. Here is my code:
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();
The values return as i expect, but i think there is something wrong with my query, it says Incorrect syntax near the keyword 'where'. Can anyone see the problem?
Thanks