晕死了....各位大侠帮忙解决一下吧!!!!!!!!!
Public Function getDataTable(ByVal sql As String) As DataTable
Try
Dim sqlAdapter1 As SqlDataAdapter = New SqlDataAdapter(sql, cnn)
Dim dataSet As DataSet = New DataSet
sqlAdapter1.Fill(dataSet)
Return dataSet.Tables(0)
sqlAdapter1.Dispose()
Catch ex As Exception
errors.Log(ex.ToString)
Return New DataTable
Finally
Close()
End Try
End Function
.................................................
2007-1-9 6:15:54System.NullReferenceException: 未将对象引用设置到对象的实例。
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.SqlClient.SqlCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.FillFromCommand(Object data, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
at machine.DBoperate.getDataTable(String sql)
2007-1-9 16:52:33System.InvalidOperationException: 已有打开的与此连接相关联的 DataReader,必须首先将它关闭。
at System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean executing)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.SqlClient.SqlCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.FillFromCommand(Object data, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
at machine.DBoperate.getDataTable(String sql)
2007-1-9 16:52:37System.InvalidOperationException: 内部连接致命错误。
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.SqlClient.SqlCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.FillFromCommand(Object data, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
at machine.DBoperate.getDataTable(String sql)
[解决办法]
检查cnn是否在其他的地方没有关闭。
[解决办法]
2007-1-9 16:52:33System.InvalidOperationException: 已有打开的与此连接相关联的 DataReader,必须首先将它关闭。
你是不是在别的地方用到了DataReader 读数据了然后没关掉啊
[解决办法]
Dim sqlAdapter1 As SqlDataAdapter = New SqlDataAdapter(sql, cnn)里的cnn哪来的,
SqlConnection对象有没有创建
[解决办法]
你是不是整个页面共用一个连接,检查一下在不同的时期调用该方法时 cnn的状态.
[解决办法]
这么简单的函数写的好乱!
Public Function getDataTable(ByVal sql As String) As DataTable
using cnn=创建新的连接() '例如new sqlConnection(.....)来创建连接
Dim sqlAdapter1 As SqlDataAdapter = New SqlDataAdapter(sql, cnn)
Dim dataSet As DataSet = New DataSet
sqlAdapter1.Fill(dataSet)
end using
Return dataSet.Tables(0)
End Function
[解决办法]
Public Function getDataTable(ByVal sql As String) As DataTable
using cnn=创建新的连接() '例如new sqlConnection(.....)来创建连接
Dim sqlAdapter1 As SqlDataAdapter = New SqlDataAdapter(sql, cnn)
Dim dataSet As DataSet = New DataSet
sqlAdapter1.Fill(dataSet)
return dataSet.Tables(0)
end using
End Function
数据库连接必须在这个函数结束时即刻自动close。
[解决办法]
帮LZ顶
[解决办法]
列名 '******市**********公司 ' 无效。
是因为你查询的时候两边没有加 '号
[解决办法]
已有打开的与此连接相关联的 DataReader,必须首先将它关闭
=========
datareader没有关闭,另一个datareder又要用这个连接打开.
------解决方案--------------------
未将对象引用设置到对象的实例。
at System.Data.SqlClient.SqlCommand.ExecuteReader
=======这个就很难讲了.
[解决办法]
这个cnn是怎么声明的.
[解决办法]
建议lz还是检查cnn的状态..
[解决办法]
这是个公用类吧?
代码贴出来看看.
特别是返回datareader的地方.
行为要用CloseConnection
cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection