比如有个asp.net(vb.net)连接sqlserver2000数据库的连接模块(module):ModuleMdlCommonPublictxtSQLAsString'存放SQL语句PublicDBSetAsDataSet'查询得到的记录集PublicErrorMsgAsString'存放错误信息PublicFunctionExecuteSQL(ByValstrSQLAsString,ByReferrMsgAsString)AsDataSetDimcnnAsSqlClient.SqlConnectionDimcmdAsNewSqlClient.SqlCommand()DimadptAsSqlClient.SqlDataAdapterDimrstAsNewDataSet()DimSplitSQL()AsStringerrMsg=""TrySplitSQL=Split(strSQL)cnn=NewSqlClient.SqlConnection("datasource=(local);initialcatalog=urp;userid=sa;pwd=1234"
)IfInStr("INSERT,DELETE,UPDATE",UCase$(SplitSQL(0))
)Thencmd.Connection=cnncmd.Connection.Open()cmd.CommandText=strSQLcmd.ExecuteNonQuery()Elseadpt=NewSqlClient.SqlDataAdapter(strSQL,cnn)adpt.Fill(rst)ExecuteSQL=rstEndIfCatchexAsExceptionerrMsg=ex.MessageFinallyrst=Nothingcnn=NothingEndTryEndFunctionEndModule调用时在asp.net后台写上txtSQL="SELECT*FROMuser";DBSet=ExecuteSQL(txtSQL,ErrorMsg)就可以查询db返回结果了。