首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

VB6自定义类型与MSSQL进展数据交换

2013-12-13 
VB6自定义类型与MSSQL进行数据交换Private Type ParameterValuesReals(4) As SingleBools As IntegerEnd T

VB6自定义类型与MSSQL进行数据交换
Private Type ParameterValues
Reals(4) As Single
Bools As Integer
End Type

Private Type PIConfig
Steps As Integer
Owned As Integer
ImmedRelease As Integer
Continue As Integer
Parameter(32) As ParameterValues
End Type

Private Type ParameterReal
Name As String
EU As String
OpMin As Single
OpMax As Single
End Type

Private Type ManualStepParameter
Enable As Boolean
Scaled As Boolean
Value As Single
Parameter As ParameterReal
End Type

Private Type ManualStep
Prompt As String
Parameter As ManualStepParameter
AN_Enable As Boolean
AN_Name As String
OpANRequired As Boolean
CmndTO As Integer
End Type

Private Type WaitPhase
ResetAccOnHold As Boolean
Preset As Integer
End Type

Private Type Config
Name As String
Version As String
Version_Date As String
Author As String
Description As String
StepNames(32) As String
PauseableStep As Integer
PIs(20) As PIConfig
ManualPhaseSteps As Integer
ManualPhase(32) As ManualStep
WaitPhaseSteps As Integer
WaitPhase(32) As WaitPhase
StepTOPre(32) As Integer
StepTOResetOnHold As Integer
EditPtrCmnd As Integer
SemiAutomatic As Boolean
HoldOnFaults As Boolean
End Type
=====================================================
以上为我自定义的类型,上面config类型为我想要把这些数据和SQL进行数据交换的对象,要求是能够根据config下的Name进行保存数据(当点保存时判定Name名在SQL表中是否存在,如果存在则提示“名称已存在,请确认”,否则正常写入SQL)。
本人新入手VB和SQL,对此不太熟悉,麻烦各位大神帮我写一写,谢谢了!
[解决办法]
你可以考虑用XML数据保存到你的数据库中
[解决办法]
程序编译后是没有Name的,类型的名字只是地址偏移量的代号,无法用于和数据字段匹配!!
[解决办法]
以下是个人理解编写出来的,不知道是不是您想要的。呵呵。

Option Explicit

Private Type Config
    Name As String
    Version As String
    Version_Date As String
    Author As String
    Description As String
    StepNames(32) As String
    PauseableStep As Integer
    PIs(20) As PIConfig
    ManualPhaseSteps As Integer
    ManualPhase(32) As ManualStep
    WaitPhaseSteps As Integer
    WaitPhase(32) As WaitPhase
    StepTOPre(32) As Integer
    StepTOResetOnHold As Integer
    EditPtrCmnd As Integer
    SemiAutomatic As Boolean
    HoldOnFaults As Boolean
End Type

Private xConfig As Config
Private SQL As String
Private aCon As New ADODB.Connection
Private aCmd As New ADODB.Command
Private aRec As New ADODB.Recordset

Private Sub cmdSave_Click()
    '>>>连接数据库
    aCon.Open "连接字符串"
    aCon.CursorLocation = adUseClient
    Set aCmd.ActiveConnection = aCon
    
    
    SQL = "SELECT 1 FROM sysobjects where xtype='u' and name='" & xConfig.Name & "'"
    aCmd.CommandText = SQL
    Set aRec = aCmd.Execute
    If Not aRec.EOF Then
        MsgBox "名称已存在,请确认"
        Exit Sub
    Else
        '>>>>Create Table
        SQL = "CREATE TABLE " & xConfig.Name & "(YourFields NVARCHAR(100......)"
        aCmd.CommandText = SQL
        aCmd.Execute


        
        '>>>>INSERT INTO TABLE
        SQL = "INSERT "
        aCmd.CommandText = SQL
        aCmd.Execute
    End If
End Sub

热点排行