Display the result of a stored procedure in a GridView using a checkbox

I need to display the results of a stored procedure in gridview using a checkbox. But my result set is not tied to gridview as I am working on an existing portal that has connection strings embedded in the dll. Here is my code ..

protected void Go_Rgn_Click(object sender, EventArgs e)
{
    SecurityController SC = new SecurityController();
    plhTable.Visible = true;
    plhChoose.Visible = false;
    plhForm.Visible = false;
    string Rgn = afRgn.Text;
    DataTable dt = new DataTable();

    dt=SC.BindGridView(Rgn);
    if (dt.Rows.Count > 0)
    {
        gvAll.DataSource = dt;
        gvAll.DataBind();
    }
}

The compiler produces an error that

Cannot convert void type to System.Data.DataTable

Please advise me about this.

Data level:

public DataTable BindGridView(string rgn)
{
    string spdName = "spd_get_default_region";
    DbCommand cmd = DB.GetStoredProcCommand(spdName);
    DB.AddInParameter(cmd, "Rgn", DbType.String, rgn);
    return  DB.ExecuteNonQuery(cmd);
}
+3
source share
1 answer

You are trying to return empty when the expected output is a data table:

Error in line:

return  m_WorkoutPortal_DB.ExecuteNonQuery(cmd);

ExecuteNonQuery does not return a data table

Edit:

public DataTable BindGridView(string rgn)
{
    string spdName = "spd_get_default_region";

    DbCommand cmd = m_WorkoutPortal_DB.GetStoredProcCommand(spdName);
    m_WorkoutPortal_DB.AddInParameter(cmd, "Rgn", DbType.String, rgn);

    SqlDataAdapter da = new SqlDataAdapter(cmd); // Create a SQL Data Adapter and assign it the cmd value. 

    DataTable dt = new DataTable(); // Create a new Data table
    da.Fill(dt); // Fill the data table with the results from the query

    return dt; // return the data table
 }


protected void Go_Rgn_Click(object sender, EventArgs e)
{
  SecurityController SC = new SecurityController();
  plhTable.Visible = true;
  plhChoose.Visible = false;
  plhForm.Visible = false;
  string Rgn = afRgn.Text;

  gvAll.DataSource = SC.BindGridView(Rgn);
  gvAll.DataBind();
}
+2
source

All Articles