你直接返回ds不就行了吗?
不然你调用的地方要ds这么办呢?
不然你调用的地方要ds这么办呢?
解决方案 »
- 关于调用数据库中的图片的问题
- Detailview 中绑定Dropdownlist时出现错误???
- vs2005 服务器资源管理器连接数据库问题
- 跨方法实现数据共享,也就是说,有一个变量在三个或更多的方法中调用,并保存状态...不用session和静态变量.
- java里的super 相当c#里的什么关键字
- 谁有OWC控件的使用资料?
- SQL 触发器 保持唯一的怎么实现啊?~
- 利用微软的ASPMENU菜单组件的XML文件如何在程序中创建?
- 想实现一个动态form表单,将页面选中的项目内容提交到后台,应该用什么实现?
- treeview 跨页面提交问题
- 服务器发布网站,提示安全性异常错误,怎么解决啊?
- 菜鸟第一个网页 局域网内别人看不到
ds.Tables[0]
到底是什么??
return dt;
俩ID和你想的一样么?
{
DataSet ds = new DataSet();
string strsql = "select a.*,b.* from book_message a inner join book_user b on a.[user_id]=b.[user_id]" + strcond;
Database db = DatabaseFactory.CreateDatabase();
DbCommand cmd = db.GetSqlStringCommand(strsql);
try
{
ds = db.ExecuteDataSet(cmd);
}
catch (Exception ex)
{
ds = null;
this.Errmsg = ex.Message.ToString();
} return ds; ///这里提示出错
}
-------
同意!
还有
ds = db.ExecuteDataSet(cmd);这个 db.ExecuteDataSet返回的是什么呢;
只能证明查询数据库没有结果集.....把SQL语句改下放到SQL查询分析器下运行...看看有问题没....
如果SQL语句没问题...那就只能是你的查询数据库代码问题了.....
{
ds = db.ExecuteDataSet(cmd);
}
catch (Exception ex)
{
this.Errmsg = ex.Message.ToString();
}代码跟踪一下上面的代码是不是异常了
ds的值都为 null
sql语句显示正常。。都不知道这是什么原因了
ds的值都为 null
sql语句显示正常。。都不知道这是什么原因了
---------------------------------------------------------只有去看ExecuteDataSet方法了
strcond?是什么东西,贴出来看看
判断输入查询条件或是不输入查询条件的SQL语句
{
string strsql = "select a.*,b.* from book_message a inner join book_user b on a.[user_id]=b.[user_id]" + strcond;
Database db = DatabaseFactory.CreateDatabase();
DbCommand cmd = db.GetSqlStringCommand(strsql);
DataSet ds = null;
try
{
ds = db.ExecuteDataSet(cmd);
}
catch
{
ds = null;
} return ds;
}看看这样行不行啊!!!!
return ds.Tables[0]; ///这里提示出错
所以应该判断一下ds.Tables.Count的值再返回结果
{
ds = db.ExecuteDataSet(cmd);
}
catch (Exception ex)
{
this.Errmsg = ex.Message.ToString();
}建议去掉 try catch 个人估计的查询有异常发生
{
return ds.Tables[0];
}
要强制转换为sql类型的连接dbdatabase要转换sqldatabase
string strsql = "select a.*,b.* from book_message a inner join book_user b on a.[user_id]=b.[user_id]" + strcond;
这句sql strcond 应该是string变量吧?
我以前也碰到这个问题.
"" 里加个空格!这样写:string strsql = "select a.*,b.* from book_message a inner join book_user b on a.[user_id]=b.[user_id] " + strcond;
string strsql = "select a.*,b.* from book_message a inner join book_user b on a.[user_id]=b.[user_id]" + strcond;
在执行这条语句后,将strsql变量的值全部复制到查询分析器中运行,如果它能等到结果,说明你返回记录集的方法有问题.
除了SQL查询导致结果集为空以外,请问还有其它原因导致结果集为空吗?有可能在你引用的方法里面,判断了某个条件,条件不满足则直接return null,所以你得到的DataSet是null
其他的,好像没有了……
Try
Dim Conn As SqlConnection
Conn = New SqlConnection(strSqlConn)
Dim SqlCmd As SqlCommand = New SqlCommand(sql, Conn)
Conn.Open()
Dim sqlDr As SqlDataReader = SqlCmd.ExecuteReader(CommandBehavior.CloseConnection)
Return sqlDr
Catch ex As Exception
Throw (ex)
End Try
End Function
----
Public Function GetSqlDataSource(ByVal sql As String) As SqlDataSource
Try
Dim SqlDs As SqlDataSource
SqlDs = New SqlDataSource
SqlDs.ConnectionString = strSqlConn
SqlDs.SelectCommand = sql
Return SqlDs
Catch ex As Exception End Try
End Function
------
Public Function GetDataSet(ByVal sql As String) As DataSet
Try
Dim Conn As SqlConnection
Conn = New SqlConnection(strSqlConn)
Dim sqlDa As SqlDataAdapter = New SqlDataAdapter(Sql, Conn)
Dim ds As DataSet = New DataSet
Conn.Open()
sqlDa.Fill(ds, "a")
Conn.Close()
sqlDa.Dispose()
Conn.Dispose()
GetDataSet = ds
Catch ex As Exception
Throw (ex)
End Try
End Function
DataTable Dt=db.ExecuteDataSet(cmd).tables[0];
那有可能连接数据库出错...
没有加connection吧,参数...