比如有個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返回結果了。
比如有個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返回結果了。