复制代码代码如下:
cmd=NewSqlCommand(sql,conn)
cmd.ExecuteNonQuery()
sql="INSERTINTOmyTable(myId,myName,myAddress,myValues)"+_
"VALUES(1003,'【孟宪会之精彩世界】之三','http://xml.sz.luohuedu.net/',99)"
cmd=NewSqlCommand(sql,conn)
cmd.ExecuteNonQuery()
sql="INSERTINTOmyTable(myId,myName,myAddress,myValues)"+_
"VALUES(1004,'【孟宪会之精彩世界】之四','http://www.erp800.com/net_lover/',100)"
cmd=NewSqlCommand(sql,conn)
cmd.ExecuteNonQuery()
CatchaeAsSqlException
MessageBox.Show(ae.Message.ToString())
EndTry
EndSub
'创建存储过程
PrivateSubCreateSPBtn_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)_
HandlesCreateSPBtn.Click
sql="CREATEPROCEDUREmyProcAS"+"SELECTmyName,myAddressFROMmyTableGO"
ExecuteSQLStmt(sql)
EndSub
'创建视图
PrivateSubCreateViewBtn_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)_
HandlesCreateViewBtn.Click
sql="CREATEVIEWmyViewASSELECTmyNameFROMmyTable"
ExecuteSQLStmt(sql)
EndSub
'修改表
PrivateSubbtnAlterTable_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)_
54com.cn
HandlesbtnAlterTable.Click
sql="ALTERTABLEMyTableADDnewColdatetimeNOTNULLDEFAULT(getdate())"
ExecuteSQLStmt(sql)
EndSub
'创建规则和索引
PrivateSubbtnCreateOthers_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)_
HandlesbtnCreateOthers.Click
sql="CREATEUNIQUEINDEX"+"myIdxONmyTable(myName)"
ExecuteSQLStmt(sql)
sql="CREATERULEmyRule"+"AS@myValues>=90AND@myValues<9999"
ExecuteSQLStmt(sql)
EndSub
'删除表
PrivateSubbtnDropTable_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)_
HandlesbtnDropTable.Click
DimsqlAsString="DROPTABLEMyTable"
ExecuteSQLStmt(sql)
EndSub
复制代码代码如下:
'浏览表数据
PrivateSubbtnViewData_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)_
HandlesbtnViewData.Click
conn=NewSqlConnection(ConnectionString)
Ifconn.State=ConnectionState.OpenThen
conn.Close()
EndIf
ConnectionString="DataSource=.;InitialCatalog=MyDataBase;UserId=sa;Password=;"
conn.ConnectionString=ConnectionString
conn.Open()
DimdaAsNewSqlDataAdapter("SELECT*FROMmyTable",conn)
DimdsAsNewDataSet("myTable")
da.Fill(ds,"myTable")
DataGrid1.DataSource=ds.Tables("myTable").DefaultView
EndSub
'浏览存储过程
PrivateSubbtnViewSP_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)_
HandlesbtnViewSP.Click
conn=NewSqlConnection(ConnectionString)
Ifconn.State=ConnectionState.OpenThen
conn.Close()
EndIf
ConnectionString="DataSource=.;InitialCatalog=MyDataBase;UserId=sa;Password=;"
conn.ConnectionString=ConnectionString
conn.Open()
DimdaAsNewSqlDataAdapter("myProc",conn)
DimdsAsNewDataSet("SP")
da.Fill(ds,"SP")
DataGrid1.DataSource=ds.DefaultViewManager
EndSub
'浏览视图
PrivateSubbtnViewView_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)_
HandlesbtnViewView.Click
conn=NewSqlConnection(ConnectionString)
Ifconn.State=ConnectionState.OpenThen
conn.Close()
EndIf
ConnectionString="DataSource=.;InitialCatalog=MyDataBase;UserId=sa;Password=;"
conn.ConnectionString=ConnectionString
conn.Open()
DimdaAsNewSqlDataAdapter("SELECT*FROMmyView",conn)
DimdsAsNewDataSet()
da.Fill(ds)
DataGrid1.DataSource=ds.DefaultViewManager
EndSub
PrivateSubExecuteSQLStmt(ByValsqlAsString)
conn=NewSqlConnection(ConnectionString)
'打开连接
Ifconn.State=ConnectionState.OpenThen
conn.Close()
EndIf
ConnectionString="DataSource=.;InitialCatalog=MyDataBase;UserId=sa;Password=;"
conn.ConnectionString=ConnectionString
conn.Open()
cmd=NewSqlCommand(sql,conn)
Try
cmd.ExecuteNonQuery()
CatchaeAsSqlException
MessageBox.Show(ae.Message.ToString())
EndTry
EndSub
EndClass