问题
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
im totally new with vb .net. im doing a simple project for my term work.
please explain to me how to insert values.
im getting this errer ORA-01008: not all variables bound....
im using vb.net VS 2008 oracle database oledb connection
回答1:
Use question (?) placeholder instead of named parameters because you're using System.Data.OleDb
. I'd suggest to download ODP.NET - Oracle Data Provider for .NET.
For instance,
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
....
来源:https://stackoverflow.com/questions/13122243/inserting-values-in-a-oracle-databse-using-oledb-in-vb-net-vs-2008