请问我怎么把查询出来的字段值取出来啊??
string STR = string.Format("select mobile as abc from smspgm1 where id = {0}", i);
为什么得到的是select mobile as abc from smspgm1 where id =217;而我想只得到mobile的值???请问怎么做???
...全文
20616打赏收藏
执行SQL语句;
请问我怎么把查询出来的字段值取出来啊?? string STR = string.Format("select mobile as abc from smspgm1 where id = {0}", i); 为什么得到的是select mobile as abc from smspgm1 where id =217;而我想只得到mobile的值???请问怎么做???
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();
为什么得到的是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 的值