使用VB .NET中的OLEDB插入Oracle数据,vs 2008


Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim insertOk As Boolean = True
        Dim con1 As OleDb.OleDbConnection
        Dim cmd As OleDb.OleDbCommand
        Dim query As String
        Dim temp As Integer
        con1 = New OleDb.OleDbConnection("Provider=MSDAORA.1;Data Source=localhost;Persist Security Info=True;Password=sys;User ID=nitishok")
        con1.Open()
        query = "insert into APPLICANTS(APPLICANT_ID,FIRST_NAME,MIDDLE_NAME,LAST_NAME,SEX,F_H,TOWN,TALUKA,DISTRICT,LANDLINE,MOBILE,BLOOD_GROUP,EDU,DOB) values(:aid,:fn,:mn,:ln,:s,:fh,:tw,:tl,:ds,:land,:mob,:bg,:edu,:dob)"
        cmd = New OleDb.OleDbCommand(query, con1)
        cmd.Parameters.Add(":aid", OleDb.OleDbType.VarChar).Value = TextBox7.Text
        cmd.Parameters.Add(":fn", OleDb.OleDbType.LongVarChar).Value = TextBox1.Text
        cmd.Parameters.Add(":mn", OleDb.OleDbType.LongVarChar).Value = TextBox12.Text
        cmd.Parameters.Add(":ln", OleDb.OleDbType.LongVarChar).Value = TextBox11.Text
        cmd.Parameters.Add(":s", OleDb.OleDbType.LongVarChar).Value = ComboBox1.Text
        cmd.Parameters.Add(":fh", OleDb.OleDbType.LongVarChar).Value = TextBox2.Text
        cmd.Parameters.Add(":tw", OleDb.OleDbType.LongVarChar).Value = TextBox10.Text
        cmd.Parameters.Add(":tl", OleDb.OleDbType.LongVarChar).Value = TextBox8.Text
        cmd.Parameters.Add(":ds", OleDb.OleDbType.LongVarChar).Value = TextBox9.Text
        cmd.Parameters.Add(":land", OleDb.OleDbType.LongVarChar).Value = TextBox5.Text
        cmd.Parameters.Add(":mob", OleDb.OleDbType.LongVarChar).Value = TextBox6.Text
        cmd.Parameters.Add(":bg", OleDb.OleDbType.LongVarChar).Value = ComboBox2.Text
        cmd.Parameters.Add(":edu", OleDb.OleDbType.LongVarChar).Value = TextBox4.Text
        cmd.Parameters.Add(":dob", OleDb.OleDbType.Date).Value = DateTimePicker1.Value
        cmd.CommandType = CommandType.Text
        temp = cmd.ExecuteNonQuery()

        If temp > 0 Then
            MessageBox.Show("Record Added!")
        Else
            MessageBox.Show("Record Not Added!")
        End If
        con1.Close()
    End Sub

我全新使用vb .net。我为我的学期工作做一个简单的项目。

请向我解释如何插入值。

im获取此错误ORA-01008:并非所有变量都绑定....

IM使用VB.NET vs 2008 Oracle数据库 OLEDB连接

使用问题(?)占位符,而不是命名参数,因为您使用的是System.Data.OleDb。我建议下载odp.net- .net的oracle数据提供商。

例如,

query = "insert into APPLICANTS(APPLICANT_ID,FIRST_NAME) values(?,?)"
cmd.Parameters.Add("?", OleDb.OleDbType.VarChar,30).Value = TextBox7.Text
cmd.Parameters.Add("?", OleDb.OleDbType.LongVarChar,40).Value = TextBox1.Text
....

相关内容

  • 没有找到相关文章

最新更新