简单问题请教:sqlserver查询

huhaha7171 2004-06-09 10:40:45
有一个表名:ts_i,里面有au,ma,pl等若干个字段(au的类型为char).
我想找出所有au为East640302的记录,只要au,ma,pl三个字段。
以下是我的一段代码,总是报错:
***************************************************************
string sqlTs = "select au,ma,pl from ts_i where au=East640302";
SqlDataAdapter da1 = new SqlDataAdapter( sqlTs ,cnToTs);//连结cntots也正确
ds = new DataSet();//ds前面已定义
try
{
da1.Fill(ds, "Ts" );
}
catch(Exception ee)
{
MessageBox.Show(ee.ToString());
}
*******************************************
报错的信息:
system.data.sqlcilent.sqlexception:
invalid column name 'east640302'.
at .....executereader(....)
at......fillfromcommand(...)
at......fill(....)
at...


...全文
61 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
sukey00 2004-06-09
  • 打赏
  • 举报
回复
string sqlTs = "select au,ma,pl from ts_i where au='East640302';
renrenqq 2004-06-09
  • 打赏
  • 举报
回复
string sqlTs = @"select au,ma,pl from ts_i where au='East640302'";
SqlDataAdapter da1 = new SqlDataAdapter( sqlTs ,cnToTs);//连结cntots也正确
ds = new DataSet();//ds前面已定义
try
{
da1.Fill(ds, "Ts" );
}
catch(Exception ee)
{
MessageBox.Show(ee.ToString());
}
极速小王子 2004-06-09
  • 打赏
  • 举报
回复
就是加上单引号!
hongchao 2004-06-09
  • 打赏
  • 举报
回复
同意楼上。
对于SQL SERVER里的字符字段及时间字段,查询时都在常量两边应加上单引号。
string sqlTs = "select au,ma,pl from ts_i where au='east640302' and [时间字段] = '2004/6/9 10:50:00'"
北京的雾霾天 2004-06-09
  • 打赏
  • 举报
回复
string sqlTs = "select au,ma,pl from ts_i where au=East640302";
写为:
string sqlTs = "select au,ma,pl from ts_i where au='East640302'";
试试:)
加个''

110,545

社区成员

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

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

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