我想把数据库中的参数拿到asp.net 中用
如:我把string strsql定义为如下:
declare @number int
set @number = (select count(h) from test )
这个SQL语句,,
我想把@number拿到函数中用
应该怎么办,,
是不是根SqlParameter有关的,,
应该怎么用啊,,
如:我把string strsql定义为如下:
declare @number int
set @number = (select count(h) from test )
这个SQL语句,,
我想把@number拿到函数中用
应该怎么办,,
是不是根SqlParameter有关的,,
应该怎么用啊,,
解决方案 »
- 请问如何用asp.net控制在word里面划一条红色的横线?
- 后台无法设置GridView中控件的Enable属性
- 多文件上传出错"无法访问已关闭的文件"
- asp.net 调用 ActiveX 控件的问题
- [200分] 高分求救困扰了一周的问题,如解决了可再加分。
- 页面确认提交问题
- DataBinding:“System.Data.DataRowView”不包含名为“resource_url”的属性。
- 读取数据到asp:TextBox然后更新数据
- 小问题,急急急!!!
- Module.vb 中如何写 Response.write ?
- 是否缺少 using 指令或程序集引用?
- session过期后如何自动返回到登陆页面?
执行sql 语句结束以后
取得该参数的值 。
string strsql = "select count(h) as count from test ";
SqlCommand cmd = new SqlCommand(strsql,conn);
SqlDataReader dr= cmd..ExecuteReader()
if(dr.Read())
{
aa=dr["count"].ToString();
}
如果不中的话,给count加单引号看看,没用过
最后,
dr.Dispose();
conn.Close();
{
....
conn.Close();
}
"select 'count'=count(h) from test"
我也应该好好看看书了,想法就是生成一列,然后将列值多出来
string strSQL="declare @number int \n"
+"select @number = (select count(h) from test )";
SqlCommand cmd = new SqlCommand(Con,strSQL);
Con.Open();
int Number=(int)cmd.ExecuteScalar()
Con.Close();
发现我的定义变量是多此一举的,,
还弄成什么没实例化,,
现在只需这样就可以的,,当然先要谢谢各位了
"
string strSql = "select count(h) from test";
string strConnection = "server=localhost;database=mydatabase;uid=sa;password=sa";
SqlConnection objConnection = new SqlConnection(strConnection);
SqlCommand objCommand = new SqlCommand(strSql,objConnection);
objConnection.Open();
int number = (int) objCommand.ExecuteScalar();
//SqlCommand.ExecuteScalar()返回执行查询结果中的第一行的第一列
Response.Write("sdfds"+number+"<br>");
"
但是我不知道为什么把strSql换成
“declare @number int select @number=(seleclt count(h) from test)”
为什么不可以,,
照例他也应该返回的是
一行一列的,,
有什么不同啊