Gridview 和 DbCommand

发布于 2024-08-22 17:14:57 字数 1649 浏览 6 评论 0原文

我必须用 dbcommand 填充 gridview 。

我编写的代码是:

EntityConnection entityConnection = (EntityConnection)db.Connection;
        DbConnection storeConnection = entityConnection.StoreConnection;
        storeConnection.Open();
DbCommand command = storeConnection.CreateCommand();
    command.CommandType = CommandType.StoredProcedure;
    command.Parameters.Add(new SqlParameter("StatoID", DropDownListStato.SelectedValue));
    command.Parameters.Add(new SqlParameter("InizioPeriodo", DateTime.Parse(TxtIntervalloDataInizio.Text + " 00:00")));
    command.Parameters.Add(new SqlParameter("FinePeriodo", DateTime.Parse(TxtIntervalloDataFine.Text + " 23:59")));
    command.Parameters.Add(new SqlParameter("AccountID", ddlDipendenti.SelectedValue));
    command.Parameters.Add(new SqlParameter("Prenotazioni", ChkPrenotazioni.Checked.ToString()));
    command.Parameters.Add(new SqlParameter("PrenotazioniEffettuate", DropDownListPrenotazioniEffettuate.SelectedValue == "True" ? 1 : 0));
    command.Parameters.Add(new SqlParameter("UscitaServizio", DropDownListUscitePerServizio.SelectedValue == "True" ? 1 : 0));

    command.CommandText = "up_missioni_get_data";        
    GridView1.DataSource = command.ExecuteReader();   

命令正确返回行,但网格视图未填充。 为什么 ? 网格视图的标题是:

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" OnRowDataBound="GridView1_RowDataBound"
            AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="MissioneID"  
            PageSize="20" Width="100%" CellPadding="4" CellSpacing="1"
              GridLines="None" >

我该怎么办?

谢谢

i have to fill a gridview with a dbcoommand.

The code that i have wrote is:

EntityConnection entityConnection = (EntityConnection)db.Connection;
        DbConnection storeConnection = entityConnection.StoreConnection;
        storeConnection.Open();
DbCommand command = storeConnection.CreateCommand();
    command.CommandType = CommandType.StoredProcedure;
    command.Parameters.Add(new SqlParameter("StatoID", DropDownListStato.SelectedValue));
    command.Parameters.Add(new SqlParameter("InizioPeriodo", DateTime.Parse(TxtIntervalloDataInizio.Text + " 00:00")));
    command.Parameters.Add(new SqlParameter("FinePeriodo", DateTime.Parse(TxtIntervalloDataFine.Text + " 23:59")));
    command.Parameters.Add(new SqlParameter("AccountID", ddlDipendenti.SelectedValue));
    command.Parameters.Add(new SqlParameter("Prenotazioni", ChkPrenotazioni.Checked.ToString()));
    command.Parameters.Add(new SqlParameter("PrenotazioniEffettuate", DropDownListPrenotazioniEffettuate.SelectedValue == "True" ? 1 : 0));
    command.Parameters.Add(new SqlParameter("UscitaServizio", DropDownListUscitePerServizio.SelectedValue == "True" ? 1 : 0));

    command.CommandText = "up_missioni_get_data";        
    GridView1.DataSource = command.ExecuteReader();   

the command return correctly the rows but the grid view isn't filled.
Why ?
The header of grid view is:

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" OnRowDataBound="GridView1_RowDataBound"
            AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="MissioneID"  
            PageSize="20" Width="100%" CellPadding="4" CellSpacing="1"
              GridLines="None" >

how can i do?

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

森末i 2024-08-29 17:14:57

忘记了 GridView1.Databind();

forgot GridView1.Databind();

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文