从vb.net执行sql命令

时间:2013-09-23 10:02:46

标签: sql vb.net oracle

这是VB.Net中的代码。我正在从vb10到oracle 10g进行连接。问题是我的代码在sql prompt中正常工作

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

0 个答案:

没有答案