//错误 5 无法将类型“WebProject.Model.LeftSecond”转换为“T” E:\WebProbject\DAL\LeftSecondDAL.cs 32 27 DAL接口using System;
using System.Collections.Generic;
using System.Text;
using WebProject.Model;namespace WebProject.DAL
{
public interface IDAL<T>
{
/// <summary>
/// 返回对象集合对象
/// </summary>
/// <returns>LeftFirst集合</returns>
List<T> QueryAll(); /// <summary>
/// 返回对象集合对象
/// </summary>
/// <param name="parentId">parentId</param>
/// <returns>LeftSecond集合</returns>
List<T> QueryById(string Id);
}
}实现类:
using System;
using System.Collections.Generic;
using System.Text;
using WebProject.Model;
using System.Data.SqlClient;namespace WebProject.DAL
{
public class LeftSecondDAL<T>:WebProject.DAL.IDAL<T>
{
#region IDAL<LeftSecond> 成员 public List<T> QueryAll()
{
return new List<T>();
} public List<T> QueryById(string Id)
{
string sql = "select * from LeftSecond where parentId=@parentId";
SqlConnection con = DBUtil.SQLHelper.getConnection();
SqlDataReader sdr = DBUtil.SQLHelper.Query(con, System.Data.CommandType.Text, sql, new SqlParameter[] { new SqlParameter("@parentId", Id) });
List<T> nodes = new List<T>();
LeftSecond node = null;
while (sdr.Read())
{
node = new LeftSecond();
node.ParentId = Convert.ToInt32(sdr["parentId"].ToString());
node.Text = sdr["text"].ToString();
node.Url = sdr["url"].ToString();
node.Target = sdr["target"].ToString();
nodes.Add((T)node); //无法将类型“WebProject.Model.LeftSecond”转换为“T”
}
DBUtil.SQLHelper.CloseCon(con);
return nodes;
} #endregion
}
}
using System.Collections.Generic;
using System.Text;
using WebProject.Model;namespace WebProject.DAL
{
public interface IDAL<T>
{
/// <summary>
/// 返回对象集合对象
/// </summary>
/// <returns>LeftFirst集合</returns>
List<T> QueryAll(); /// <summary>
/// 返回对象集合对象
/// </summary>
/// <param name="parentId">parentId</param>
/// <returns>LeftSecond集合</returns>
List<T> QueryById(string Id);
}
}实现类:
using System;
using System.Collections.Generic;
using System.Text;
using WebProject.Model;
using System.Data.SqlClient;namespace WebProject.DAL
{
public class LeftSecondDAL<T>:WebProject.DAL.IDAL<T>
{
#region IDAL<LeftSecond> 成员 public List<T> QueryAll()
{
return new List<T>();
} public List<T> QueryById(string Id)
{
string sql = "select * from LeftSecond where parentId=@parentId";
SqlConnection con = DBUtil.SQLHelper.getConnection();
SqlDataReader sdr = DBUtil.SQLHelper.Query(con, System.Data.CommandType.Text, sql, new SqlParameter[] { new SqlParameter("@parentId", Id) });
List<T> nodes = new List<T>();
LeftSecond node = null;
while (sdr.Read())
{
node = new LeftSecond();
node.ParentId = Convert.ToInt32(sdr["parentId"].ToString());
node.Text = sdr["text"].ToString();
node.Url = sdr["url"].ToString();
node.Target = sdr["target"].ToString();
nodes.Add((T)node); //无法将类型“WebProject.Model.LeftSecond”转换为“T”
}
DBUtil.SQLHelper.CloseCon(con);
return nodes;
} #endregion
}
}
解决方案 »
- 点云数据如何进行3D建模
- c# 如何画树形结构图,不用treeview控件
- 一个关于有条件截取substring的问题,请求帮忙
- 请教一个结合gridview的SQL数据库功能
- 利用Enterprise Library和DataSet(或者DataTable)结合进行批量更新
- 在派生类中调用基类函数,构造函数,属性访问私有变量时,访问的是基类的还是派生累类继承的??
- 请教有关在WinXP上(非AD)创建Windows系统本地用户,及其设置用户权限的问题
- 专家分??
- treeview 单击右键时如何获得目前右键选中的节点?
- 页面完全显示前显示等待页面怎么做啊?请大虾帮忙
- 在gridview上得到以下结果
- 通俗的解释下.trim()
nodes.Add(node);//试试这个