WEB开发网
开发学院数据库MSSQL Server 快速搭建ERP数据库框架 阅读

快速搭建ERP数据库框架

 2007-12-27 15:30:21 来源:WEB开发网   
核心提示:那么,如何用程序实现自动生成数据库框架?现在,快速搭建ERP数据库框架(2),我们就来创建一个这样的程序,在本程序中共建立5个按钮分别是:建立数据库,建立表,建立约束

那么,如何用程序实现自动生成数据库框架?现在,我们就来创建一个这样的程序。在本程序中共建立5个按钮分别是:建立数据库,建立表,建立约束,建立存储过程,显示数据。实现的代码如下:

Public Class Form1
  Inherits System.Windows.Forms.Form
  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
    Dim con As New OleDb.OleDbConnection("Provider=SQLOLEDB.1;Integrated
Security=SSPI;Persist Security Info=False;Initial Catalog=Northwind;Data
Source=.;Use Procedure for Prepare=1;Auto Translate=True;Packet
Size=4096;Workstation ID=J;Use Encryption for Data=False;Tag with column collation
when possible=False")
    con.Open()
    Dim cmd As New OleDb.OleDbCommand("create database jk", con)
    cmd.ExecuteNonQuery()
    con.Close()
'建立数据库
  End Sub
  Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
    Dim con2 As New OleDb.OleDbConnection("Provider=SQLOLEDB.1;Integrated
Security=SSPI;Persist Security Info=False;Initial Catalog=jk;Data Source=.;Use
Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=J;Use
Encryption for Data=False;Tag with column collation when possible=False")
    con2.Open()
    Dim cmd As New OleDb.OleDbCommand("create table kk(id int identity(1,1) not
null constraint id primary key,name char(4) not null)", con2)
    cmd.ExecuteNonQuery()
    Dim cmd2 As New OleDb.OleDbCommand("create table pp(id int not null,ads
char(20) null)", con2)
    cmd2.ExecuteNonQuery()
    con2.Close()
'建立2个表
  End Sub
  Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
    Dim con2 As New OleDb.OleDbConnection("Provider=SQLOLEDB.1;Integrated
Security=SSPI;Persist Security Info=False;Initial Catalog=jk;Data Source=.;Use
Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=J;Use
Encryption for Data=False;Tag with column collation when possible=False")
    con2.Open()
    Dim com As New OleDb.OleDbCommand("alter table pp add primary key (id)",
con2)
    com.ExecuteNonQuery()
    con2.Close()
'建立约束
  End Sub
  Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
    Dim con2 As New OleDb.OleDbConnection("Provider=SQLOLEDB.1;Integrated
Security=SSPI;Persist Security Info=False;Initial Catalog=jk;Data Source=.;Use
Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=J;Use
Encryption for Data=False;Tag with column collation when possible=False")
    con2.Open()
    Dim com As New OleDb.OleDbCommand("create proc procname as select * from
kk", con2)
    com.ExecuteNonQuery()
    con2.Close()
'建立存储过程
  End Sub
  Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button5.Click
    Dim con2 As New OleDb.OleDbConnection("Provider=SQLOLEDB.1;Integrated
Security=SSPI;Persist Security Info=False;Initial Catalog=jk;Data Source=.;Use
Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=J;Use
Encryption for Data=False;Tag with column collation when possible=False")
    Dim com As New OleDb.OleDbCommand("procname", con2)
    Dim da As New OleDb.OleDbDataAdapter()
    da.SelectCommand = com
    Dim ds As New DataSet()
    da.Fill(ds)
    DataGrid1.DataSource = ds
'显示数据
  End Sub
End Class

Tags:快速 搭建 ERP

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接