我不会查询了

lanxing106 2008-08-29 12:02:43
我想获取sit.instrcode、sit.pointid、it.instrtype 字段中的数据,最后封装到和一个类中,并每次添加到ArrayList中。


public static ArrayList readPointId(string stationId ,string oracleConnStr)
{
ArrayList list = new ArrayList();
string sql = "select sit.instrcode,sit.pointid,it.instrtype from qzdata.qz_dict_stationinstruments sit,QZDATA.QZ_DICT_INSTRUMENTS it where sit.instrcode like'312%' and sit.stationid='" + stationId + "' and it.instrcode=sit.instrcode";
using (OracleConnection conn = new OracleConnection(oracleConnStr))
{
conn.Open();
using (OracleCommand cmd = new OracleCommand(sql, conn))
{
using (OracleDataReader dr = cmd.ExecuteReader())
{
while(dr.Read())
{
Point p = new Point();
p.InstrCode = dr.GetString(0);
p.PointId = dr.GetString(1);
p.InstrType = dr.GetString(2);
list.Add(p);
}
}
}
}
return list;
}


但Point封装后的值和数据库中的值有很大的出入:

数据库中查询如下:
INSTRCODE POINTID INSTRTYPE
3121504 1 FHD-2

程序封装后如下:

p.InstrCode 3121504
p.PointId FHD-2
p.InstrType NULL

我怀疑我的查询有问题,我是新手不知道怎么改,求教了~!
...全文
52 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
jiang_jiajia10 2008-08-29
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 wuyi8808 的回复:]
C# code p.InstrCode = dr.GetString(0);
p.PointId = dr.GetInt32(1);
p.InstrType = dr.GetString(2);
[/Quote]
lanxing106 2008-08-29
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 wuyi8808 的回复:]
p.PointId = dr.GetInt(1);
[/Quote]
谢谢 我的PointId字段是varchar的,不过已经解决了!
是我马虎了 我写错了 把PointID 值给instrType了 真晕死我了

下面是错误的代码:

public class Point
{
private string instrCode;
private string pointId;
private string instrType;

public Point()
{
//
// TODO: 在此处添加构造函数逻辑
//
}

public string InstrCode
{
get { return instrCode; }
set { instrCode = value; }
}

public string PointId
{
get { return pointId; }
set { pointId = value; }
}

public string InstrType
{
get { return instrType; }
set { pointId = value; }
}

}



zhpfeiqq 2008-08-29
  • 打赏
  • 举报
回复
从1开始吧
wuyi8808 2008-08-29
  • 打赏
  • 举报
回复
                       p.InstrCode = dr.GetString(0);
p.PointId = dr.GetInt32(1);
p.InstrType = dr.GetString(2);
wuyi8808 2008-08-29
  • 打赏
  • 举报
回复
p.PointId = dr.GetInt(1);

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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