⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmhwbm.frm

📁 用vb和SQLSERVER编译的关于数据库的源程序例子。
💻 FRM
字号:
VERSION 5.00
Begin VB.Form frmHwbm 
   Caption         =   "货物资料新增"
   ClientHeight    =   2355
   ClientLeft      =   4245
   ClientTop       =   3150
   ClientWidth     =   6030
   LinkTopic       =   "Form2"
   ScaleHeight     =   2355
   ScaleWidth      =   6030
   Begin VB.CommandButton Command 
      Caption         =   "保存(&S)"
      Height          =   345
      Index           =   2
      Left            =   4830
      TabIndex        =   7
      Top             =   90
      Width           =   1125
   End
   Begin VB.Frame Frame 
      Height          =   2145
      Left            =   30
      TabIndex        =   1
      Top             =   90
      Width           =   4695
      Begin VB.TextBox Text 
         Height          =   330
         Index           =   3
         Left            =   1110
         TabIndex        =   10
         Top             =   270
         Width           =   2025
      End
      Begin VB.TextBox Text 
         Height          =   330
         Index           =   2
         Left            =   1110
         TabIndex        =   8
         Top             =   1620
         Width           =   2025
      End
      Begin VB.TextBox Text 
         Height          =   330
         Index           =   0
         Left            =   1110
         TabIndex        =   3
         Top             =   720
         Width           =   2025
      End
      Begin VB.TextBox Text 
         Height          =   330
         Index           =   1
         Left            =   1110
         TabIndex        =   2
         Top             =   1170
         Width           =   3315
      End
      Begin VB.Label Label 
         Caption         =   "货物单价:"
         Height          =   195
         Index           =   3
         Left            =   210
         TabIndex        =   9
         Top             =   1680
         Width           =   825
      End
      Begin VB.Label Label 
         Caption         =   "货物编码:"
         Height          =   195
         Index           =   0
         Left            =   180
         TabIndex        =   6
         Top             =   780
         Width           =   825
      End
      Begin VB.Label Label 
         Caption         =   "货物名称:"
         Height          =   195
         Index           =   1
         Left            =   180
         TabIndex        =   5
         Top             =   1230
         Width           =   825
      End
      Begin VB.Label Label 
         Caption         =   "货物分类:"
         Height          =   195
         Index           =   2
         Left            =   180
         TabIndex        =   4
         Top             =   330
         Width           =   825
      End
   End
   Begin VB.CommandButton Command 
      Caption         =   "退出(&X)"
      Height          =   345
      Index           =   1
      Left            =   4830
      TabIndex        =   0
      Top             =   510
      Width           =   1125
   End
End
Attribute VB_Name = "frmHwbm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

'定义文本框索引对应的常量
Const TxtHwBmFlCode = 3
Const TxtHwBmCode = 0
Const TxtHwBmMc = 1
Const TxtHwBmPrice = 2

'定义命令按钮索引对应的常量
Const CmdSave = 2
Const CmdExit = 1

'命令按钮事件处理,Index为命令按钮的索引值
Private Sub Command_Click(Index As Integer)
On Error GoTo Errorhandle

   Select Case Index
   Case CmdSave
         SaveRecord
   Case CmdExit
         Unload Me
   End Select

Exit Sub
Errorhandle:
   MsgBox Err.Description
End Sub

'保存处理,将界面上的数据写到数据库
Private Sub SaveRecord()
   Dim Conn As ADODB.Connection
   Dim SqlStr As String, ConnStr As String
On Error GoTo Errorhandle
   
   '构造连接字符串
   ConnStr = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Password=;Initial Catalog=fiterp;Data Source=ERP002"

   '产生新的Conn对象,与数据库建立连接
   Set Conn = New ADODB.Connection
   Conn.ConnectionString = ConnStr
   Conn.Open
   
   '执行Insert语句将界面上的数据写到数据库
   Conn.Execute "INSERT HWBMREC(HWBMFLCODE,HWBMCODE,HWBMMC,HWBMPRICE,HWBMDAT) VALUES('" & Trim(Text(TxtHwBmFlCode).Text) & "','" & Trim(Text(TxtHwBmCode).Text) & "','" & Trim(Text(TxtHwBmMc).Text) & "'," & CStr(Val(Text(TxtHwBmPrice).Text)) & ",GETDATE())"
   
Exit Sub
Errorhandle:
   Err.Raise vbObjectError + 1, , Err.Description
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -