注册 登录
编程论坛 VB6论坛

请教各位大佬看看有无错误,SQL运行结果:rs.Open(sql, conn)参数类型不正确,或不在可以接受的范围之内,或与其他参数冲突

leokk 发布于 2019-06-23 19:48, 1568 次点击
Public Class Form9
    Dim conn As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    Dim rss As New ADODB.Recordset
    Dim str As String
    Dim sql As String
    Private Sub Form9_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        conn = OpenConn()

        sql = "select 药品编号 from 药品信息"
        ComboBox2.Items.Clear()
        rs.Open(sql, conn)
        Do While Not rs.EOF
            str = Trim(rs(0).Value)
            ComboBox2.Items.Add(str)
            rs.MoveNext()
        Loop
        rs.Close()
        sql = "select 病人编号 from 病人信息 "
        ComboBox1.Items.Clear()
        rs.Open(sql, conn)
        Do While Not rs.EOF
            str = Trim(rs(0).Value)
            ComboBox1.Items.Add(str)
            rs.MoveNext()
        Loop
        rs.Close()
    End Sub


    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        If Trim(ComboBox1.SelectedItem) = "" Then
            MsgBox("请选择病人!")
            Exit Sub
        End If
        If Trim(ComboBox2.SelectedItem) = "" Then
            MsgBox("请选择药品!")
            Exit Sub
        End If
        sql = "insert into 配药单 values('" & Trim(ComboBox1.SelectedItem) & "','" & Trim(ComboBox2.SelectedItem) & "',GETDATE(),'" & Trim(TextBox2.Text) & "')"
        rs.Open(sql, conn)

        sql = "update 病人信息 set 总费用 = 总费用 + " & Int(Trim(TextBox2.Text)) * Int(Trim(TextBox1.Text)) & " where 病人编号 = '" & Trim(ComboBox1.SelectedItem) & "'"
        rs.Open(sql, conn)

        MsgBox("添加成功")


        Me.Close()
        CloseConn(conn)

    End Sub

    Private Sub TextBox1_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox1.TextChanged
    End Sub

    Private Sub TextBox2_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox2.TextChanged
        If (TextBox2.Text <> "") Then
            Label5.Text = "总价格为" & Int(Trim(TextBox2.Text)) * Int(Trim(TextBox1.Text)) & "元"
        End If

    End Sub

    Private Sub Button4_Click(sender As System.Object, e As System.EventArgs) Handles Button4.Click
        Me.Close()
    End Sub

    Private Sub ComboBox2_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
        sql = "select 价格 from 药品信息 where 药品编号 = '" & Trim(ComboBox2.SelectedItem) & "'"
        rs.Open(sql, conn)
        TextBox1.Text = Trim(rs(0).Value)
        rs.Close()
    End Sub

    Private Sub Label4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub
End Class
     
1 回复
#2
leokk2019-06-23 19:49
打错了,
是vs运行结果
1