public int CalculateRecord()
{
int intCount;
string strCount; strCount = "select count(*) as co from fileup";
SqlCommand MyComm = new SqlCommand(strCount, mycon);
SqlDataReader dr = MyComm.ExecuteReader();
if (dr.Read())
{
intCount = Int32.Parse(dr["co"].ToString());
}
else
{
intCount = 0;
}
dr.Close();
return intCount;
}
{
int intCount;
string strCount; strCount = "select count(*) as co from fileup";
SqlCommand MyComm = new SqlCommand(strCount, mycon);
SqlDataReader dr = MyComm.ExecuteReader();
if (dr.Read())
{
intCount = Int32.Parse(dr["co"].ToString());
}
else
{
intCount = 0;
}
dr.Close();
return intCount;
}
解决方案 »
- WCF 调用服务器 出现找不到方法
- c# 多线程通信问题,高手请进哦!!
- 关于Entity Framework 操作的一个问题
- 求教一下关于C#程序运行时顿卡的问题,各位大大能帮下我么?
- vs2005中的sql问题,很简单,非常简单
- 散分了 vs.net安装部署深入研究
- bool aa; DateTime bb; int cc;如何判断aa,bb,cc是否有值?
- 如何用C#+SQL语句建一个数据库
- remoting中 客户端激活对象 的问题?????
- 中断了两天,这是我的C#学习笔记,敬请高手指导
- mainmenu当有下级菜单的时候click不起作用
- (100分求)用户权限分配可以通过编程实现吗
public int CalculateRecord()
{
int intCount;
string strCount; strCount = "select count(*) as co from fileup";
SqlCommand MyComm = new SqlCommand(strCount, mycon);
mycon.Open(); //打开连接
SqlDataReader dr = MyComm.ExecuteReader();
if (dr.Read())
{
intCount = Int32.Parse(dr["co"].ToString());
}
else
{
intCount = 0;
}
dr.Close();
mycon.Close(); //关闭连接
return intCount;
}
首先生成SqlConnection,然后打开此连接。
SqlCommand MyComm = new SqlCommand(strCount, mycon);
MyComm.Connection.Open();
SqlDataReader dr = MyComm.ExecuteReader();
if (dr.Read())
mycon.Open();