当前位置: 代码迷 >> Sql Server >> 获取数据表查询出的列数值,该怎么处理
  详细解决方案

获取数据表查询出的列数值,该怎么处理

热度:5   发布时间:2016-04-27 11:35:35.0
获取数据表查询出的列数值
我的语句是这样的
  string str1 = ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString.ToString();
  SqlConnection con = new SqlConnection(str1);
  con.Open();
  string stri1 = "select count(*) from syscolumns where=id=object_id('" + Session["table"] + "')";
  SqlCommand com = new SqlCommand(stri1, con);
  com.ExecuteNonQuery();
我要把查询出来的数据表列数赋值给一个int型的变量,怎么做?

------解决方案--------------------
string connstring=//连接字符串
string sql=“"//数据库查询语句
connection con=new connection(connstring);
Command cmd=new Command(sql,con);
con.open();
SqlDataReader dr=cmd.ExcuteReader;
if(dr.read())
{
定义int变量=dr[0];//}
dr.close();
con.close();
------解决方案--------------------
用 DATASET 接收后,再赋值给你的整形变量.这个你最好到C# 坛子里问一下。
------解决方案--------------------
int i = 2;
string str = "1";
i = int.Parse(str);
  相关解决方案