按照说明,我输入了以下代码,以通过使用数据列表显示结果,但参数存在问题 名称
这是方法代码
public static DataTable GetSessionByName(string Session_name)
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = Config.GetConnectionStr();
conn.Open();
//Prepare SQL Command with parameter
string sql = "Select * from Session Where Session_name =
@Session_name";
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Parameters.AddWithValue("Session_name", Session_name);
// Create data adapter
SqlDataAdapter da = new SqlDataAdapter(cmd); //Create a DataTable that
will store the result of the query
DataTable dt = new DataTable(); // this will query your database and
return the result to your datatable
da.Fill(dt);
//Close connection and release the data adapter
conn.Close();
da.Dispose();
//return the Datatable return dt;
return dt;
}
这是我尝试使用数据列表的地方
protected void btnSearch_Click(object sender, EventArgs e)
{
string SearchName = txtSearchName.Text;
DataTable dt = Class.GetSessionByName(Session_name);
dlSearch.DataSource = dt;
dlSearch.DataBind();
}
当我在按钮中输入代码时,我得到的session_name在当前上下文中不存在