gpt4 book ai didi

c# - 在带有复选框的GridView中显示存储过程的结果

转载 作者:行者123 更新时间:2023-11-30 17:12:22 25 4
gpt4 key购买 nike

我需要在带有复选框的 GridView 中显示存储过程的结果。但是我的结果集没有绑定(bind)到 gridview,因为我正在处理一个现有的门户网站,该门户网站已将连接字符串作为 dll 内置。这是我的代码..

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();
}
}

编译器抛出错误

Cannot convert type void to System.Data.DataTable

请就此提出建议。

数据访问层:

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);
}

最佳答案

当预期输出是数据表时,您正试图返回一个空值:

错误在行:

return  m_WorkoutPortal_DB.ExecuteNonQuery(cmd);

ExecuteNonQuery 不返回数据表

编辑:

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();
}

关于c# - 在带有复选框的GridView中显示存储过程的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10736004/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com