【问题标题】:Get a single value from dataSet in asp.net从 asp.net 中的 dataSet 中获取单个值
【发布时间】:2011-12-07 14:38:23
【问题描述】:

我正在查询以从 tbl_message 表中获取 Title 和 RespondBY,我想在对转发器进行数据绑定之前解密 Title。在进行数据绑定之前如何访问标题值。

string MysqlStatement = "SELECT Title, RespondBy  FROM tbl_message  WHERE tbl_message.MsgID = @MsgID";

using (DataServer server = new DataServer())
{
    MySqlParameter[] param = new MySqlParameter[1];
    param[0] = new MySqlParameter("@MsgID", MySqlDbType.Int32);
    param[0].Value = MessageID;
    command.Parameters.AddWithValue("@MsgID", MessageID);
    ds = server.ExecuteQuery(CommandType.Text, MysqlStatement, param);
}
rptList.DataSource = ds;
rptList.DataBind();


  <table style="width: 498px; color: #F5F5F5;">
        <asp:Repeater ID="rptList" runat="server">
            <HeaderTemplate>
            </HeaderTemplate>
            <ItemTemplate>
                <tr>
                    <td width="15%">
                        <b>Subject</b>
                    </td>
                    <td width="60%">
                        <asp:Label ID="lbl_Subj" runat="server" Text='<%#Eval("Title")%>' />
                    </td>
                </tr>

【问题讨论】:

  • 在您的代码中,您在“RespondBy”之后添加了额外的“,”。查询工作正常吗?

标签: c# asp.net dataset


【解决方案1】:

可能,像下面的代码部分一样,您可以获得标题并在此之前尝试此编码

rptList.DataSource = ds;
  rptList.DataBind();  

以下代码部分可以从dataset获取Title

string title = ds.Tables[0].Rows[0]["Title"].ToString();

【讨论】:

    【解决方案2】:

    不确定你所说的解密是什么意思,但如果你想通过对其应用一些逻辑来修改标题,那么你可以创建一个将标题作为输入并返回解密文本的方法,而不是将文本与标题绑定。您可以将您的标签绑定到此方法,并将其传递给 Title。

    【讨论】:

      【解决方案3】:

      字符串标题 = ds.Tables[0].Rows[0][0].ToString();

      我使用索引而不是标题名称。个人喜好。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多