无法找到表 0。---   在 System.Data.DataTableCollection.get_Item(Int32 index)
 在 Lan.DAL.DBHelper.GetDataSet(String sql, SqlParameter[] values) 位置 E:\工作项目\公司项目\三公项目\Lan.SanGong\Lan.DAL\DBHelper.cs:行号 154
   在 Lan.DAL.UserService.GetUserByUP(String userName, String password) 位置 E:\工作项目\公司项目\三公项目\Lan.SanGong\Lan.DAL\UserService.cs:行号 44
   在 

解决方案 »

  1.   

    代码
    string strSql = "select * from tl_User where F_Name=@name and F_Password=@password";
                SqlParameter[] paras ={
                new SqlParameter("@name",SqlDbType.VarChar,20),
                new SqlParameter("password",SqlDbType.VarChar,20)
            };
                paras[0].Value = userName;
                paras[1].Value = password;
                DataTable dtUserInfo = DBHelper.GetDataSet(strSql, paras);
                User userInfo = new User();
                if (dtUserInfo!=null && dtUserInfo.Rows.Count > 0)
                {
                    DataRow row = dtUserInfo.Rows[0];
                    userInfo.Key = row["F_Key"].ToString();
                    userInfo.Name = row["F_Name"].ToString();
                    userInfo.Role = row["F_Role"].ToString();
                    userInfo.Area = row["F_Area"].ToString();
                }
                return userInfo;
      

  2.   

     
    DataSet ds=DBHelper.GetDataSet(strSql, paras)???DataSetif(ds!=null && ds.DataTable.Count>0)
      DataTable dtUserInfo = DBHelper.GetDataSet(strSql, paras)[0];
      

  3.   

    DBHelper.GetDataSet(strSql, paras)这个我反回的是一个datatable
      

  4.   

    public static DataTable GetDataSet(string sql, params SqlParameter[] values)
            {
                
                    DataSet ds = new DataSet();
                    SqlCommand cmd = new SqlCommand(sql, Connection);
                    cmd.Parameters.AddRange(values);
                    SqlDataAdapter da = new SqlDataAdapter(cmd);
                    da.Fill(ds);
                    return ds.Tables[0];
                }
      

  5.   

    想问问大家,如果代码里面没有写关闭连接的语句connection.Close()。默认连接数100,有20个人登录连接数会被用尽吗?
      

  6.   

    一看你的SQL执行就是没有释放资源
      

  7.   

    public static SqlConnection Connection
            {
                get
                {
                    string connectionString = ConfigurationManager.AppSettings["ConnString"];                if (connection == null)
                    {
                        connection = new SqlConnection(connectionString);
                        connection.Open();
                    }
                    else if (connection.State == System.Data.ConnectionState.Closed)
                    {
                        connection.Open();
                    }
                    else if (connection.State == System.Data.ConnectionState.Broken)
                    {
                        connection.Close();
                        connection.Open();
                    }
                    return connection;
                }
            }
    我以为,如果不手动写关闭连接方法,如果连接数据库操作完毕之后会自动将连接放回到连接池中。现在我这样写using(SqlCommand cmd = new SqlCommand(sql, Connection))
                {
                    cmd.Parameters.AddRange(values);
                    SqlDataReader reader = cmd.ExecuteReader();
                    return reader;
                }
    会不会用完之后自动将连接释放掉,放到连接池中
      

  8.   

    用完之后不会自己释放链接,要手工释放            //实例一个数据库链接
                SqlConnection con = new SqlConnection(sqlConStr);
                //实例一个操作代理
                SqlCommand comm = new SqlCommand();
                comm.Connection = con;            //定义SQL语句
                string query = "Select N_1101 as [记录编号],N_1102 as [分类编码],N_1103 as [分类名称] From [N_1100] ORder by N_1107 DESC";
                comm.CommandText = query;
                //实例一个数据库操作表
                DataTable dt=new DataTable();
                try
                {
                    con.Open();
                    //实例一个数据填充对象,using也是释放资源的一种方式
                    using (SqlDataAdapter sda = new SqlDataAdapter())
                    {
                        sda.SelectCommand = comm;                    //将数据填充到dt中
                        sda.Fill(dt);
                        sda.Dispose();
                    }            }
                catch (Exception e)
                {
                    Response.Write("数据绑定失败!<br/>");
                    Response.Write(e.Message);
                }
                finally//不管执行成功与否,都要记得关闭数据库链接,释放资源
                {
                    comm.Dispose();
                    con.Close();
                    con.Dispose();
                }
      

  9.   

    public static SqlConnection Connection你这个是静态的连接对象引起的吧
      

  10.   

    如果我用public static SqlConnection Connection的话手动close释放可以吗,应为我现在项目里面很多用的是静态方法,如果要改会改动很大
      

  11.   

    using(SqlCommand cmd = new SqlCommand(sql, Connection))
                {
                    cmd.Parameters.AddRange(values);
                    SqlDataReader reader = cmd.ExecuteReader();
                    return reader;
                }如果我这样写是否能确保连接using中使用到连接的都会关闭并放到连接池中(无论是否出现异常情况)?
      

  12.   

    这种问题,如果不用new,还有什么好的解决办法没有??
      

  13.   

    我目前只知道用new,其他的你网上搜搜吧
      

  14.   

    是否是包含在using里面的语句都能被释放?这样写可以吗,会出现问题吗? using (SqlConnection Connection = new SqlConnection(""))
                {
                    Connection.Open();
                    SqlCommand cmd = new SqlCommand(safeSql, Connection);
                    int result = cmd.ExecuteNonQuery();
                    Connection.Close();//这一句是否可以不用加
                    return result;            }
      

  15.   

    http://topic.csdn.net/u/20100220/11/dc3cc806-b887-478c-9f15-26076b47ff9b.html?69249看看这个
      

  16.   

    使用using后最后有了Dispose()把连接释放掉了,Dispose()应该是相当于把连接直接销毁了,Close()应该是只是关闭了逻辑连接并没有销毁。如果我使用了了using之后就给销毁了,不是连接池就不起作用了?每次用的时候要重新创建一个物理连接??