string strCon = "Persist Security Info=False;Integrated Security=SSPI;database=ZC_FSVR;server=."; 
SqlConnection myConn = new SqlConnection (strCon) ;     
string strCom = " SELECT * FROM sysuser" ;
DataSet ds = new DataSet() ; 
myConn.Open() ; 
SqlDataAdapter da = new SqlDataAdapter(strCom,myConn) ; 
da.Fill (ds) ; 
myConn.Close ( ) ; 

解决方案 »

  1.   

    异常出现在哪里。
    如果是myConn.Open() ;
    先看看本机是不是能连通数据库
      

  2.   

    运行到这句,da.Fill (ds) ; 报错错误:
    未处理的“System.NullReferenceException”类型的异常出现在 system.data.dll 中。其他信息: 未将对象引用设置到对象的实例。
      

  3.   

    string strCon = "user id=sa;data source=.;persist security info=False;initial catalog=Northwind"; 
    SqlConnection myConn = new SqlConnection (strCon) ;     
    string strCom = " SELECT * FROM product" ;
    DataSet ds = new DataSet() ; 
    myConn.Open() ; 
    SqlDataAdapter da = new SqlDataAdapter(strCom,myConn) ; 
    da.Fill (ds) ; 
    myConn.Close ( ) ; 搞不懂,到底哪里错了?
      

  4.   

    你加个表名看看.da.Fill (ds,"product") ; 
      

  5.   

    SqlDataAdapter da = new SqlDataAdapter(strCom,myConn) ; 这句中断了
      

  6.   

    我这里试了一下,貌似没有什么问题。
    可能是Dll引用的问题。
      

  7.   

    检查SQLServer中权限设置。.NET信任模式的连接,在WEB中与Winform访问SQLServer的用户是不同的。改变连接字串,用sa混合验证模式。
    Driver={SQL Server};Server=.;Database=pZC_FSVR; Uid=sa;Pwd=sa;
      

  8.   

    你的strCom 只是一个字符串而已并非sqlCommand
      

  9.   

    myConn.Open() ;去掉试下
      

  10.   

    晕死,,我看是你的代码问题。。为什么要重装呢?这是你的代码:
    string strCom = " SELECT * FROM sysuser" ; 
    DataSet ds = new DataSet() ; 
    myConn.Open() ; 
    SqlDataAdapter da = new SqlDataAdapter(strCom,myConn) ; strCom能直接用来作参数?
    SqlDataAdapter 的参数类型应该是这样的吧。。
    new SqlDataAdapter(SqlCommand,SqlConnection)所以说:
    你的程序应该要改成这样。
    SqlCommand cmd = new SqlCommand(" SELECT * FROM sysuser" );
    ......SqlDataAdapter da = new SqlDataAdapter(cmd ,myConn) ; 
      

  11.   

    你看看连接字符串.
    貌似Winform和WebForm的有一点点区别
      

  12.   


    正解,web和winform还是有区别的,写法上.
      

  13.   

    SqlDataAdapter myDa = new SqlDataAdapter();
    myDa.SelectCommand = new SqlCommand(" SELECT * FROM sysuser" , myConn);
    DataSet myDs = new DataSet();
    myDa.Fill(myDs, TableName);这样。。