执行SQL语句;

chang_1 2007-07-28 11:24:46
请问我怎么把查询出来的字段值取出来啊??
string STR = string.Format("select mobile as abc from smspgm1 where id = {0}", i);
为什么得到的是select mobile as abc from smspgm1 where id =217;而我想只得到mobile的值???请问怎么做???
...全文
206 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
yzl1982 2007-07-30
  • 打赏
  • 举报
回复
我觉得楼主基础东西应该多看看,无论是.NET的不是SQL 的
blankfang 2007-07-30
  • 打赏
  • 举报
回复
同意一楼的看法!!!!!!
zhou410527 2007-07-30
  • 打赏
  • 举报
回复
string STR = string.Format("select mobile as abc from smspgm1 where id = {0}", i);

得到的只是你要执行的sql语句,只有该sql语句(select mobile as abc from smspgm1 where id =217)执行后才能得到mobile 字段的值
JL99000 2007-07-30
  • 打赏
  • 举报
回复
xiexie haonanernet
changkimkim 2007-07-30
  • 打赏
  • 举报
回复
SqlConnection conn = new SqlConnection("Server=.;Database=love;Integrated Security=SSPI");
conn.open();
SqlCommand cmd = new SqlCommand ("select mobile as abc from smspgm1 where id =217",conn);
String mobile = cmd.ExecuteScalar().ToStirng();
conn.close();
haonanernet 2007-07-30
  • 打赏
  • 举报
回复
用abc作为 mobile的别名
JL99000 2007-07-29
  • 打赏
  • 举报
回复
想问问select mobile as abc from smspgm1 where id =217 这句是什么意思呢
select mobile as abc 是什么意思?
mobile是字段名吧?那as abc 做用什么用的
yugas 2007-07-28
  • 打赏
  • 举报
回复
^_^
Jinglecat 2007-07-28
  • 打赏
  • 举报
回复
该看书就先看书~
liusong_china 2007-07-28
  • 打赏
  • 举报
回复
没有执行?..
will521 2007-07-28
  • 打赏
  • 举报
回复
用OleDbDataReade读出来,然后用dataview来接结果,然后用
mobile = dataview.table.rows[0]cell[0].tostring()
取出来。

===================================================================
中国DotNet程序员俱乐部 -- www.willsft.com

-- 中国最专业的DotNet技术社区!

技术支持群:
3354034、34857327 、24694039、19055417、35202852、2684939、37718551
===================================================================

interxyx 2007-07-28
  • 打赏
  • 举报
回复
上下文的问题,把更具体的代码帖出来,好找原因~
如何执行之类的~
lovesnow1573 2007-07-28
  • 打赏
  • 举报
回复
为什么得到的是select mobile as abc from smspgm1 where id =217;而我想只得到mobile的值???
================
select mobile as abc from smspgm1 where id =217 这个SQL 语句你并没有执行.
执行之后.才会得到 mobile de 值..

SqlConnection conn = new SqlConnection("Server=.;Database=love;Integrated Security=SSPI");
SqlDataAdapter da = new SqlDataAdapter("select mobile as abc from smspgm1 where id =217",conn);
DataSet ds = new DataSet();
da.Fill(ds);
====ds.Tables[0].rows[0]["abc"]
就是 mobile 的值
heatol 2007-07-28
  • 打赏
  • 举报
回复
还是看一下ADO.NET吧..
syuko5460 2007-07-28
  • 打赏
  • 举报
回复
得先执行才会有结果呀,没执行怎么会有结果呢。
JL99000 2007-07-28
  • 打赏
  • 举报
回复
想问问select mobile as abc from smspgm1 where id =217中的as是什么意思呢

110,499

社区成员

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

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

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