日期:2014-05-20  浏览次数:20465 次

为什么会出现这样错误??/

Public   Shared   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)
                        sqlAdapter1.Dispose()
                 
                        Return   dataSet.Tables(0)
                Catch   ex   As   Exception
                        errors.Log(ex.ToString)
                        Return   New   DataTable
       
                End   Try
        End   Function
为什么会出现这样情况   (有时会出现有时不会出现)
...............................................
未将对象引用设置到对象的实例
      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   fashions.DBoperate.getDataTable(String   sql)


------解决方案--------------------
cnn为null ?
------解决方案--------------------
cnn还没实例化把
------解决方案--------------------
IP地址是固定的吗?
------解决方案--------------------
data source= 最好写成机器名
------------------------
http://fenglin.xland.cn
------------------------