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

📄 frmhwbm.frm

📁 用vb和SQLSERVER编译的关于数据库的源程序例子。
💻 FRM
字号:
VERSION 5.00
Begin VB.Form frmHwbm 
   Caption         =   "货物资料维护"
   ClientHeight    =   3045
   ClientLeft      =   4830
   ClientTop       =   1815
   ClientWidth     =   6030
   LinkTopic       =   "Form2"
   LockControls    =   -1  'True
   ScaleHeight     =   3045
   ScaleWidth      =   6030
   Begin VB.CommandButton Command 
      Caption         =   "保存(&S)"
      Height          =   345
      Index           =   2
      Left            =   4830
      TabIndex        =   7
      Top             =   120
      Width           =   1125
   End
   Begin VB.Frame Frame 
      Height          =   2745
      Left            =   30
      TabIndex        =   1
      Top             =   90
      Width           =   4695
      Begin VB.TextBox Text 
         Height          =   330
         Index           =   4
         Left            =   1290
         TabIndex        =   11
         Top             =   420
         Width           =   2025
      End
      Begin VB.TextBox Text 
         Height          =   330
         Index           =   3
         Left            =   1290
         TabIndex        =   10
         Top             =   870
         Width           =   2025
      End
      Begin VB.TextBox Text 
         Height          =   330
         Index           =   2
         Left            =   1290
         TabIndex        =   8
         Top             =   2220
         Width           =   2025
      End
      Begin VB.TextBox Text 
         Height          =   330
         Index           =   0
         Left            =   1290
         TabIndex        =   3
         Top             =   1320
         Width           =   2025
      End
      Begin VB.TextBox Text 
         Height          =   330
         Index           =   1
         Left            =   1290
         TabIndex        =   2
         Top             =   1770
         Width           =   3315
      End
      Begin VB.Label Label 
         Caption         =   "原货物编码:"
         Height          =   195
         Index           =   4
         Left            =   180
         TabIndex        =   12
         Top             =   480
         Width           =   1005
      End
      Begin VB.Label Label 
         Caption         =   "货物单价:"
         Height          =   195
         Index           =   3
         Left            =   360
         TabIndex        =   9
         Top             =   2280
         Width           =   825
      End
      Begin VB.Label Label 
         Caption         =   "货物编码:"
         Height          =   195
         Index           =   0
         Left            =   360
         TabIndex        =   6
         Top             =   1380
         Width           =   825
      End
      Begin VB.Label Label 
         Caption         =   "货物名称:"
         Height          =   195
         Index           =   1
         Left            =   360
         TabIndex        =   5
         Top             =   1830
         Width           =   825
      End
      Begin VB.Label Label 
         Caption         =   "货物分类:"
         Height          =   195
         Index           =   2
         Left            =   360
         TabIndex        =   4
         Top             =   930
         Width           =   825
      End
   End
   Begin VB.CommandButton Command 
      Caption         =   "退出(&X)"
      Height          =   345
      Index           =   1
      Left            =   4830
      TabIndex        =   0
      Top             =   540
      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 TxtOldHwBmCode = 4
Const TxtHwBmFlCode = 3
Const TxtHwBmCode = 0
Const TxtHwBmMc = 1
Const TxtHwBmPrice = 2

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

'命令按钮点击事件处理
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 ConnStr As String
   Dim SqlStr As String
On Error GoTo Errorhandle
   
   '构造连接字符串
   ConnStr = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Password=;Initial Catalog=fiterp;Data Source=ERP002"
   
   '产生新的连接对象,与数据库建立连接
   Set Conn = New ADODB.Connection
   Conn.ConnectionString = ConnStr
   Conn.Open
   
   '启用事务
   Conn.BeginTrans
   
   '构造Update语句,使用Conn对象执行Update语句更新数据库中的数据
   SqlStr = "UPDATE HWBMREC SET HWBMFLCODE='" & Trim(Text(TxtHwBmFlCode).Text) & "',"
   SqlStr = SqlStr & "HWBMCODE='" & Trim(Text(TxtHwBmCode).Text) & "',HWBMMC='" & Trim(Text(TxtHwBmMc).Text) & "',"
   SqlStr = SqlStr & "HWBMPRICE=" & CStr(Val(Text(TxtHwBmPrice).Text)) & ",HWBMDAT=GETDATE() "
   SqlStr = SqlStr & " WHERE HWBMCODE='" & Trim(Text(TxtOldHwBmCode).Text) & "'"
   Conn.Execute SqlStr
   
   '事务提交
   Conn.CommitTrans
   
   Conn.Close
   Set Conn = Nothing
   
Exit Sub
Errorhandle:
   Conn.RollbackTrans
   Set Conn = Nothing
   Err.Raise vbObjectError + 1, , Err.Description
End Sub

⌨️ 快捷键说明

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