<栗>项目从数据库中检索 [英] <Li> item retrieve from database

查看:122
本文介绍了<栗>项目从数据库中检索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  public   void  binddata()
{
DataTable dt = new DataTable();
SqlCommand com = new SqlCommand( E_R_GET101 ,con);
com.Parameters.AddWithValue( @ Subs_cd,loggeduser.SUBSIDIARY_CD);
com.Parameters.AddWithValue(<跨度类= 代码串> <跨度类= 代码串 > @ EMPLOYEE,loggeduser.EmployeeNo);
com.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter(com);
con.Open();
da.Fill(dt);
getdata.DataSource = dt;
getdata.DataBind();
con.Close();
}



向下投票
最爱
< ; li class < span class =code-keyword> = 下拉菜单 > < a href = class = btn btn-info data-toggle = 下拉菜单 > 收件箱< span class = 徽章 < span class =code-attribute> runat = server style = color:red id = txtContactCount > 0 < / span > < span class =code-keyword>< / a >
< ul class = 下拉菜单 id = getdata runat = server >
< li class = divider > < / li >
< li > < a href = Portal_noticexD.aspx > 查看所有通知< / a > < / li >
< / ul >
< / li >



无法绑定数据,我做错了?



什么我曾尝试:



aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

解决方案

尝试使用DataSet,而不是尝试绑定到dataTable。没有看到你的其余代码就很难了,但试试这个:

  public   void  binddata()
{
DataSet ds = new DataSet();
SqlCommand com = new SqlCommand( E_R_GET101 ,con);
com.Parameters.AddWithValue(<跨度类= 代码串> <跨度类= 代码串 > @ Subs_cd,loggeduser.SUBSIDIARY_CD);
com.Parameters.AddWithValue(<跨度类= 代码串> <跨度类= 代码串 > @ EMPLOYEE,loggeduser.EmployeeNo);
com.CommandType = CommandType.StoredProcedure;
con.Open();
SqlDataAdapter da = new SqlDataAdapter(com);
da.Fill(ds);
getdata.DataSource = ds;
getdata.DataBind();
con.Close();
}



DataBind方法确保数据源绑定到控件,但是,由于您在getdata.DataSource上下文中进行数据绑定,控件应该读取数据从数据源而不需要DataBind方法...注释掉DataBind,看看会发生什么。

  //   getdata.DataBind();  



另一种选择是调用.ToList()方法。这将DataSource属性设置为包含数据的列表。

 getdata.DataSource = ds.ToList(); 


public void binddata()
    {
        DataTable dt = new DataTable();
        SqlCommand com = new SqlCommand("E_R_GET101", con);
        com.Parameters.AddWithValue("@Subs_cd", loggeduser.SUBSIDIARY_CD);
        com.Parameters.AddWithValue("@EMPLOYEE", loggeduser.EmployeeNo);
        com.CommandType = CommandType.StoredProcedure;
        SqlDataAdapter da = new SqlDataAdapter(com);
         con.Open();
         da.Fill(dt);
        getdata.DataSource = dt;
        getdata.DataBind();
        con.Close();
    }


down vote
favorite
  <li class="dropdown"><a href="#" class="btn btn-info" data-toggle="dropdown">Inbox <span class="badge"  runat="server" style="color: red" id="txtContactCount">0</span> </a>
                <ul class="dropdown-menu" id="getdata"  runat="server">
                    <li class="divider"></li>
                    <li><a href="Portal_noticexD.aspx">View all notifications</a></li>
                </ul>
            </li>


fail to bind data ,where i did wrong??

What I have tried:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

解决方案

Instead of trying to BIND to a dataTable, try a DataSet. It's difficult without seeing the rest of your code, but try this:

public void binddata()
    {
        DataSet ds = new DataSet();
        SqlCommand com = new SqlCommand("E_R_GET101", con);
        com.Parameters.AddWithValue("@Subs_cd", loggeduser.SUBSIDIARY_CD);
        com.Parameters.AddWithValue("@EMPLOYEE", loggeduser.EmployeeNo);
        com.CommandType = CommandType.StoredProcedure;
        con.Open();        
        SqlDataAdapter da = new SqlDataAdapter(com);         
        da.Fill(ds);
        getdata.DataSource = ds;
        getdata.DataBind();
        con.Close();
    }


The DataBind method ensures the datasource is bound to the control, however, since you databind within the getdata.DataSource context, the control should read the data from the datasource without the need for the DataBind Method... comment out the DataBind and see what happens.

//getdata.DataBind();


Another option is to call .ToList() method. This sets the DataSource property to a list containing the data.

getdata.DataSource = ds.ToList();


这篇关于&LT;栗&GT;项目从数据库中检索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆