计算总记示的问题,请各位帮我,谢谢了。

liuvb 2003-08-22 03:19:30
计算总记示的问题,请各位帮我,谢谢了。

public int calculateRecordcount()
{
int intCount;
string strCount = "select count(fare) as co from farelist";
SqlDataAdapter myCommand = new SqlDataAdapter(strCount,myConnection);
OleDbDataReader dr = myCommand.ExecuteReader();

if(dr.Read())
{
intCount = Int32.Parse(dr["co"].ToString());
}
else
{
intCount = 0;
}

dr.Close();
return intCount;
}

编译错误
说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。

编译器错误信息: CS0246: 找不到类型或命名空间名称“OleDbDataReader”(是否缺少 using 指令或程序集引用?)

源错误:



行 156: string strCount = "select count(fare) as co from farelist";
行 157: SqlDataAdapter myCommand = new SqlDataAdapter(strCount,myConnection);
行 158: OleDbDataReader dr = myCommand.ExecuteReader();
行 159:
行 160: if(dr.Read())


源文件: D:\wsblqkd\sales\farelist.aspx 行: 158



...全文
52 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
liuvb 2003-08-22
  • 打赏
  • 举报
回复
谢谢xrll和各位帮忙。问题解决。
xrll 2003-08-22
  • 打赏
  • 举报
回复
SqlConnection myConnection = new SqlConnection("......
xrll 2003-08-22
  • 打赏
  • 举报
回复
你的myConnection语句呢?
xrll 2003-08-22
  • 打赏
  • 举报
回复
不要用<%# count %>这种方法:
在页面放一个<asp:Label id="lb" runat="server"/>

SqlCommand myCommand = new SqlCommand(strCount, myConnection);
myCommand.Connection.Open();
Int32 count = (Int32)myCommand.ExecuteScalar();
lb.Text=count.ToString();
myCommand.Connection.Close();
liuvb 2003-08-22
  • 打赏
  • 举报
回复
行 160: myConnection.close();
此行出错
liuvb 2003-08-22
  • 打赏
  • 举报
回复
to :xrll

我是这样做的:
public int calculateRecordcount()
{

string strCount = "select count(fare) from farelist";
SqlCommand myCommand = new SqlCommand(strCount, myConnection);
myCommand.Connection.Open();
Int32 count = (Int32)myCommand.ExecuteScalar();
myConnection.close();
   }

显示记录的地方用:共有记录<%# count %>条


出错:

编译错误
说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。

编译器错误信息: CS1513: 应输入 }

源错误:



行 158: myCommand.Connection.Open();
行 159: Int32 count = (Int32)myCommand.ExecuteScalar();
行 160: myConnection.close();
行 161:    }
行 162:

编译错误
说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。

编译器错误信息: CS1513: 应输入 }

源错误:




xrll 2003-08-22
  • 打赏
  • 举报
回复
统计数量用 SqlCommand.ExecuteScalar
string strCount = "select count(fare) from farelist";
SqlCommand myCommand = new SqlCommand(strCount, myConnection);
myCommand.Connection.Open();
Int32 count = (int32)myCommand.ExecuteScalar();
myConnection.Close();
BeyondLove2000 2003-08-22
  • 打赏
  • 举报
回复
要sql就sql,要OleDb就OleDb;
还有,别忘了相应的引用
lwgj 2003-08-22
  • 打赏
  • 举报
回复

SqlDataAdapter myCommand = new SqlDataAdapter(strCount,myConnection);
改为
SqlCommand myCommand = new SqlCommand(strCount,myConnection);
liuvb 2003-08-22
  • 打赏
  • 举报
回复

我把OleDbDataReader改为SqlDataReader,还是那一行出错。谢谢各位热心帮忙。
blackcatiii 2003-08-22
  • 打赏
  • 举报
回复
SqlDataAdapter属于System.Data.SqlClient命名空间,而OleDbDataReader属于System.Data.OleDb,两个是针对不同数据库设计的,不能同时用。
ga3ga3 2003-08-22
  • 打赏
  • 举报
回复
myConnection.Open

62,025

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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