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 ( ) ;
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 ( ) ;
如果是myConn.Open() ;
先看看本机是不是能连通数据库
未处理的“System.NullReferenceException”类型的异常出现在 system.data.dll 中。其他信息: 未将对象引用设置到对象的实例。
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 ( ) ; 搞不懂,到底哪里错了?
可能是Dll引用的问题。
Driver={SQL Server};Server=.;Database=pZC_FSVR; Uid=sa;Pwd=sa;
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) ;
貌似Winform和WebForm的有一点点区别
正解,web和winform还是有区别的,写法上.
myDa.SelectCommand = new SqlCommand(" SELECT * FROM sysuser" , myConn);
DataSet myDs = new DataSet();
myDa.Fill(myDs, TableName);这样。。