(NewSqlParameter("ReturnValue",_
SqlDbType.Int,_
4,_
System.Data.ParameterDirection.ReturnValue,_
False,_
0,_
0,_
String.Empty,_
DataRowVersion.Default,_
Nothing))
Returncommand
EndFunction
'构建一个没有参数的sqlcommand
PrivateOverloadsFunctionCreateCommand(ByValsprocNameAsString)AsSqlCommand
DimcommandAsSqlCommand=NewSqlCommand(sprocName,Connection)
command.CommandType=CommandType.StoredProcedure
command.Parameters.Add(NewSqlParameter("ReturnValue",_
SqlDbType.Int,_
4,_
System.Data.ParameterDirection.ReturnValue,_
False,_
0,_
0,_
String.Empty,_
DataRowVersion.Default,_
Nothing))
Returncommand
EndFunction
PublicReadOnlyPropertyDSN()AsString
Get
Returnm_DSN
EndGet
EndProperty
PublicOverloadsFunctionRunSP(ByValsprocNameAsString)AsInt32
DimresultAsInt32
Connection.Open()
DimcommandAsSqlCommand=Me.CreateCommand(sprocName)
command.ExecuteNonQuery()
result=CType(command.Parameters("ReturnValue").Value,Int32)
Me.Connection.Close()
Returnresult
EndFunction
PublicOverloadsFunctionRunSP(ByValsprocNameAsString,ByValparameters()AsIDataParameter)AsInt32
DimresultAsInt32
Connection.Open()
DimcommandAsSqlCommand=Me.CreateCommand(sprocName,parameters)
command.ExecuteNonQuery()
result=CType(command.Parameters("ReturnValue").Value,Int32)
Me.Connection.Close()
Returnresult
EndFunction
PublicOverloadsFunctionRunSP(ByValsprocNameAsString,_
ByValparameters()AsIDataParameter,ByValDataSetAsDataSet)AsInt32
DimresultAsInt32
DimsqlDAAsNewSqlDataAdapter
Connection.Open()
sqlDA.SelectCommand=Me.CreateCommand(sprocName,parameters)
sqlDA.Fill(DataSet,"SourceTable")
result=CType(sqlDA.SelectCommand.Parameters("ReturnValue").Value,Int32)
Connection.Close()
Returnresult
EndFunction
PublicOverloadsFunctionRunSP(ByValsprocNameAsString,_
ByRefDataSet1AsDataSet)AsInt32
DimresultAsInt32
DimsqlDAAsNewSqlDataAdapter
Connection.Open()
sqlDA.SelectCommand=Me.CreateCommand(sprocName)
sqlDA.Fill(DataSet1)
result=CType(sqlDA.SelectCommand.Parameters("ReturnValue").Value,Int32)
Connection.Close()
Returnresult
EndFunction
PublicOverloadsFunctionRunSP(ByValsprocNameAsString,_
ByValparameters()AsIDataParameter,ByRefDataSetAsDataSet,ByValTableNameAsString)AsInt32
DimresultAsInt32
DimsqlDAAsNewSqlDataAdapter
Connection.Open()
sqlDA.SelectCommand=Me.CreateCommand(sprocName,parameters)
sqlDA.Fill(DataSet,TableName)
result=CType(sqlDA.SelectCommand.Parameters("ReturnValue").Value,Int32)
Connection.Close()
Returnresult
EndFunction
PublicFunctionConstruct(ByValConstructStringAsString)
m_DSN=ConstructString
EndFunction
PublicFunctionActivate()
Connection=NewSqlConnection(m_DSN)
EndFunction
PublicFunctionDeactivate()
Connection=Nothing
EndFunction
PublicSubNew()
EndSub
PublicSubNew(ByValConstrucStringAsString)
Construct(ConstrucString)
Me.Activate()
EndSub
ProtectedOverridesSubFinalize()
MyBase.Finalize()
Me.Deactivate()
EndSub
EndClass
图书查询窗体的全部代码frmBookQuery.vb
ImportsSystem.Data.SqlClient
ImportsSystem.Drawing.Printing
PublicClassfrmBookQuery
Inheritslibrary.frmBase
#Region"Windows窗体设计器生成的代码"
'此处略去...
#EndRegion
PrivateSubfrmBookQuery_Load(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesMyBase.Load
WithMe.dbgBookList
.Anchor=CType((((System.Windows.Forms.AnchorStyles.TopOrSystem.Windows.Forms.AnchorStyles.Bottom)_
OrSystem.Windows.Forms.AnchorStyles.Left)_
OrSystem.Windows.Forms.AnchorStyles.Right),System.Windows.Forms.AnchorStyles)
.BackColor=System.Drawing.Color.Snow
.BackgroundColor=System.Drawing.SystemColors.ActiveCaptionText
.CaptionVisible=False
.HeaderForeColor=System.Drawing.SystemColors.ControlText
.ReadOnly=True
EndWith
BindComboBox1()
Me.cboBook_sort.Text=""
EndSub
Functionsearch()
DimcnAsNewSqlClient.SqlConnection(cnstr)
DimcmdAsNewSqlCommand
DimdaAsSqlDataAdapter
DimdsAsNewDataSet
Withcmd
IfMe.radAllBook.Checked=TrueThen
.CommandText="searchBook"
Else
.CommandText="searchBookInlib"
EndIf
.CommandType=CommandType.StoredProcedure
.Connection=cn
EndWith
DimmBook_codeAsNewSqlParameter("@Book_code",SqlDbType.NVarChar,50)'1
DimmBook_nameAsNewSqlParameter("@Book_name",SqlDbType.NVarChar,50)'2
DimmBook_pubAsNewSqlParameter("@Book_pub",SqlDbType.NVarChar,50)'3
DimmBook_isbnAsNewSqlParameter("@Book_isbn",SqlDbType.NVarChar,50)'4
DimmBook_pubdateAsNewSqlParameter("@Book_pubdate",SqlDbType.SmallDateTime,4)
DimmBook_authorAsNewSqlParameter("@Book_author",SqlDbType.NVarChar,50)'6
DimmBook_sortAsNewSqlParameter("@Book_sort",SqlDbType.NVarChar,50)'11
Withcmd.Parameters
.Add(mBook_code)
.Add(mBook_name)
.Add(mBook_pub)
.Add(mBook_isbn)
.Add(mBook_pubdate)
.Add(mBook_author)
.Add(mBook_sort)
EndWith
'赋值
mBook_code.Value=Me.txtBook_code.Text.Trim'1
mBook_name.Value=Me.txtBook_name.Text.Trim'2
mBook_pub.Value=Me.txtBook_pub.Text.Trim'3
mBook_isbn.Value=Me.txtBook_isbn.Text.Trim'4
mBook_pubdate.Value=Me.dtpBook_pubdate.Value'5
mBook_author.Value=Me.txtBook_author.Text.Trim'6
mBook_sort.Value=Me.cboBook_sort.Text.Trim'11
da=NewSqlDataAdapter(cmd)
Try
da.Fill(ds)
ds.Tables(0).Columns(0).Caption="图书条码号"
Me.dbgBookList.DataSource=ds.Tables(0)
Me.Label8.Text="共检索到"+ds.Tables(0).Rows.Count.ToString+"条记录"
CatchexAsException
MessageBox.Show(ex.Message)
Finally
cn.Close()
IfNotcnIsNothingThen
cn.Dispose()
EndIf
EndTry
EndFunction
FunctionBindComboBox1()
DimcnLib2004AsSqlConnection
DimcmdbooksortAsSqlCommand
DimdrBooksortAsSqlDataReader
cnLib2004=NewSqlConnection(cnstr)
cmdbooksort=NewSqlCommand
Withcmdbooksort
.CommandType=CommandType.StoredProcedure
.Connection=cnLib2004
.CommandText="selectBookSort"
EndWith
Try
cnLib2004.Open()
drBooksort=cmdbooksort.ExecuteReader
DimmyarrAsNewArrayList
WhiledrBooksort.Read
myarr.Add(drBooksort.Item(0))
EndWhile
Me.cboBook_sort.DataSource=myarr
上一篇:
ASP_net仪器设备管理系统设计与实现(论文和程序)
下一篇:
秋天是疼痛的