我的sql语句是这样写的
select b.BLName,l.BLName from bscategory as b inner join BLCategory as l on b.BLID=l.BLID
题目要求我把表里面b.BLName,l.BLName值都要拿出来,我该怎么赋值勒?我在实体类中加了一列了,我赋值就出错了!!
select b.BLName,l.BLName from bscategory as b inner join BLCategory as l on b.BLID=l.BLID
题目要求我把表里面b.BLName,l.BLName值都要拿出来,我该怎么赋值勒?我在实体类中加了一列了,我赋值就出错了!!
解决方案 »
- HttpWebRequest编码问题
- <在线等>垃圾回收问题-2
- VS 2005 Team System 补丁下载地址
- Winform安装程序如何实现第二次运行时候提示修复或卸载(同一个程序的不同版本间)?
- winform 中音频文件的播放不了...求大家都来给指教!!!!
- sql server 2005 装不成功
- 未能为数据库'四频道主'中的对象'control_launcher_store'分配空间,因为文件组'PRIMARY'已满!!!???什么意思?
- Windows服务访问网络磁盘驱动的问题
- DataGrid问题,列标题太长啦,如果不将列宽加大,肯定是不能完全显示出来,这样的就只能借助于 Tooltip 。也就是当鼠标移到列标题上时,
- 有懂Matrox Imaging Library(MIL)的吗?最初级问题
- WPF xaml界面添加AutoComplateBox报错, 但是代码添加AutoComplateBox不会错
- 大牛进来帮帮忙啊, 一个很无语的问题。。。。
可以用DataAdapter取到Dataset里, 在从DataSet里取值
string queryString =
"SELECT CustomerID, CompanyName FROM dbo.Customers";
SqlDataAdapter adapter = new SqlDataAdapter(queryString, connection);DataSet customers = new DataSet();
adapter.Fill(customers, "Customers");以上代码来自msdn:
http://msdn.microsoft.com/en-us/library/bh8kx08z.aspx再取值
DataTable table = customers["Customers"];
foreach(DataRow row in table.Rows)
{
string customerid = row["CustomerID"];
string companyName = row["CompanyName"];
.....
}以上代码手写的。
{
string queryString =
"SELECT OrderID, CustomerID FROM dbo.Orders;"; using (SqlConnection connection =
new SqlConnection(connectionString))
{
SqlCommand command =
new SqlCommand(queryString, connection);
connection.Open(); SqlDataReader reader = command.ExecuteReader(); // Call Read before accessing data.
while (reader.Read())
{
Console.WriteLine(String.Format("{0}, {1}",
reader[0], reader[1]));
} // Call Close when done reading.
reader.Close();
}
}以上代码来自msdn:
http://msdn.microsoft.com/zh-cn/library/system.data.sqlclient.sqldatareader(v=vs.80).aspx
{
public string ID { get; set; } public string Name { get; set; }
} public class BScategory : Base
{
public BScategory()
{
this.entity = new BLCategory();
}
public BLCategory entity { get; set; }
} public class BLCategory : Base
{
public BLCategory()
{
this.entity = new BScategory();
} public BScategory entity { get; set; }
}
public class BScategoryDAO
{
public IList<BScategory> RetrieveAll(IDataAccess dataAccess, string connstr)
{
IList<BScategory> lists = new List<BScategory>();
using (IDbConnection conn = Helper.OpenConnection(dataAccess, connstr))
{
string sql = string.Format("select b.BLName,l.BLName from bscategory as b inner join BLCategory as l on b.BLID=l.BLID");
IDataReader reader = dataAccess.ExecuteReader(conn, CommandType.Text, sql, null);
while (reader.Read())
{
lists.Add(Builder(reader));
}
}
return lists;
} private BScategory Builder(IDataReader reader)
{
BScategory entity = new BScategory();
entity.entity.Name = Helper.GetString(reader, "BLName");
entity.Name = Helper.GetString(reader, "BLName");
return entity;
}