Hi, I have the following gridview in asp .Net
<asp:GridView ID="grid1" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="False" CssClass="table table-bordered bs-table"
allowpaging="True" ShowFooter="True" BackColor="White" BorderColor="White" DataKeyNames="">
I had created a query with SqlDataSource but it was not what I wanted and I need the SQL query of the server's server, and create it in a button with onclick event, so that when I clicked it, it will show me the records in the table:
protected void Mostrar_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["cn"].ToString());
string sql = "SELECT bla bla.. WHERE(Sem.Semana = '52') AND(Cab.Cod_user = '@cod');
SqlCommand cmd = new SqlCommand(sql, con);
cmd.Parameters.Add("@cod", SqlDbType.VarChar, 5);
cmd.Parameters["@cod"].Value = Session["Cod_user"];
con.Open();
cmd.ExecuteNonQuery();
SqlDataReader rdr = cmd.ExecuteReader();
grid1.DataSource = rdr;
grid1.DataBind();
}
but it shows me the error of the title by these lines .....
grid1.DataSource = rdr;
grid1.DataBind();