0

这是我在VB.Net. 我正在连接vb10到 oracle 10g。问题是我的代码在sql promptas

SQL> insert into product values(pid_inc(),'name',' desc ',101,'"c:\imgloc','brand ',1,10)

但是当我尝试从 vb 访问它时它停止工作。这是为什么?我的VB代码是:

Dim con As New OleDb.OleDbConnection("Provider=MSDAORA.1;User ID=jon;password=snow;Data Source=KAUSTUBH-PC;Persist Security Info=False")
con.Open()
name = TextBox1.Text
desc = TextBox2.Text
price = Val(TextBox3.Text)
available = Val(TextBox4.Text)
brand = TextBox5.Text
cat = ComboBox1.Text

If (name <> "") Then
    nameflg = True
Else
    nameflg = False
    MsgBox(" product name cannot be empty")
End If

If (available > 0) Then
    availableflg = True
Else
    availableflg = False
    MsgBox("quantity cannot be 0")
End If

If (brand <> "") Then
    brandflg = True
Else
    brandflg = False
    MsgBox(" insert brand name")
End If

If (cat <> "") Then
    catflg = True
Else
    catflg = False
    MsgBox("pleaese select categoty")
End If
If (nameflg And logoflg And brandflg And catflg And availableflg) Then
    query = "Select cat_id from category where cat_name='" + cat + "'"
    Dim cmd As New OleDb.OleDbCommand(query, con)
    x = cmd.ExecuteScalar().ToString
    cat_id = Val(x)
    query = "insert into product values(pid_inc(),'" & name & "','" & desc & "'," & price & ",'" & imgloc & "','" & brand & "'," & cat_id & "," & available & ")"
    Dim cmd1 As New OleDb.OleDbCommand(query, con)
    cat_id = cmd1.ExecuteNonQuery()
    If (cat_id = 0) Then
        MsgBox("Record not inserted properly ....try again")
    Else
        MsgBox("Record inserted successfully")
    End If
'Else
'   MsgBox("please fill the fields properly")
End If

End Sub
4

0 回答 0