三层结构的一个存储问题

flhc2010 2010-01-22 02:16:17
我在做三层结构时遇到了这么一个问题
无法从int转换成string
BLL.cop.company bll = new BLL.cop.company();
int tpID = Convert.ToInt32(this.DataList1.DataKeys[e.Item.ItemIndex].ToString());
DataSet dp = bll.GetModel(tpID);



public Maticsoft.Model.company GetModel(string typeID)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select * from company ");
strSql.Append(" where typeID=@typeID");//@companyid 获取的id。
SqlParameter[] parameters = {
new SqlParameter("@typeID", SqlDbType.Int)};
parameters[0].Value = typeID;
Maticsoft.Model.company model = new Maticsoft.Model.company();
DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
model.typeID = typeID;
if (ds.Tables[0].Rows.Count > 0)
{
model.companyname = ds.Tables[0].Rows[0]["companyname"].ToString();
model.companylink = ds.Tables[0].Rows[0]["companylink"].ToString();
return model;
}
else
{
return null;
}
}

这个问题怎么解决啊,我把代码贴上了
...全文
112 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
flhc2010 2010-01-22
  • 打赏
  • 举报
回复
这个问题暂时解决了,下面问题又来了,我另外开贴
flhc2010 2010-01-22
  • 打赏
  • 举报
回复
[Quote=引用 19 楼 xujiaoxiang 的回复:]
Maticsoft.Model.company dp = bll.GetModel(tpID.ToString());
[/Quote]

???????????这个这个高手啊,看来你提点的是,我去试试看
xujiaoxiang 2010-01-22
  • 打赏
  • 举报
回复
Maticsoft.Model.company dp = bll.GetModel(tpID.ToString());
xujiaoxiang 2010-01-22
  • 打赏
  • 举报
回复
Maticsoft.Model.company = bll.GetModel(tpID.ToString());

入参和返回值类型都不对,搞什么呢?
flhc2010 2010-01-22
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 koukoujiayi 的回复:]
int tpID = Convert.ToInt32(this.DataList1.DataKeys[e.Item.ItemIndex].ToString());
DataSet dp = bll.GetModel(tpID);


public Maticsoft.Model.company GetModel(string typeID)
        {

一个是传int,接受的string!!!
[/Quote]


高手啊,谢谢,我把string改成int也报错是不是还要改其他的地方啊
ziniu123 2010-01-22
  • 打赏
  • 举报
回复
ere
flhc2010 2010-01-22
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 danjiewu 的回复:]
DataSet dp = bll.GetModel(tpID.ToString());

[/Quote]
错误 1 无法将类型“Maticsoft.Model.company”隐式转换为“System.Data.DataSet” E:\wangzhiwang\tzweb\Web\WebForm3.aspx.cs 29 30 Web


兄弟啊,咋这样了呢?
koukoujiayi 2010-01-22
  • 打赏
  • 举报
回复
int tpID = Convert.ToInt32(this.DataList1.DataKeys[e.Item.ItemIndex].ToString());
DataSet dp = bll.GetModel(tpID);


public Maticsoft.Model.company GetModel(string typeID)
{

一个是传int,接受的string!!!
flhc2010 2010-01-22
  • 打赏
  • 举报
回复
自己再顶顶吧
Aslangg 2010-01-22
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 sozdream 的回复:]
这问题和三层有啥关系...

public Maticsoft.Model.company GetModel(string typeID)
看, 这方法参数是string


DataSet dp = bll.GetModel(tpID);
再看, 你传入的tpID是啥? 是int, 当然报错....
[/Quote]
丿
ziniu123 2010-01-22
  • 打赏
  • 举报
回复
10
flhc2010 2010-01-22
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 koukoujiayi 的回复:]
6楼抱歉!!好像看错了!!
[/Quote]


没事没事
flhc2010 2010-01-22
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 sozdream 的回复:]
这问题和三层有啥关系...

public Maticsoft.Model.company GetModel(string typeID)
看, 这方法参数是string


DataSet dp = bll.GetModel(tpID);
再看, 你传入的tpID是啥? 是int, 当然报错....
[/Quote]

TOSTRING ()还要转换么
koukoujiayi 2010-01-22
  • 打赏
  • 举报
回复
6楼抱歉!!好像看错了!!
flhc2010 2010-01-22
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 sandyxxx 的回复:]
typeID数据库里是什么类型的 数字类型???
[/Quote]

数字类型
koukoujiayi 2010-01-22
  • 打赏
  • 举报
回复
int tpID = Convert.ToInt32(this.DataList1.DataKeys[e.Item.ItemIndex].Value.ToString());

或有多个主健的话:
int tpID = Convert.ToInt32(this.DataList1.DataKeys[e.Item.ItemIndex].Values[0].ToString());
龙翔飞雪 2010-01-22
  • 打赏
  • 举报
回复
这问题和三层有啥关系...

public Maticsoft.Model.company GetModel(string typeID)
看, 这方法参数是string


DataSet dp = bll.GetModel(tpID);
再看, 你传入的tpID是啥? 是int, 当然报错....
danjiewu 2010-01-22
  • 打赏
  • 举报
回复
DataSet dp = bll.GetModel(tpID.ToString());
  • 打赏
  • 举报
回复
typeID数据库里是什么类型的 数字类型???
abaochen 2010-01-22
  • 打赏
  • 举报
回复
我想表达的意思是 select *from company where typeID(company表里的一个字段)=类别ID
加载更多回复(1)

111,120

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧