insert into Access DB

  • Thread starter Thread starter Buz Waitz
  • Start date Start date
B

Buz Waitz

Ok, I'm a beginner. I need help.
I've set up an oledbdataadapter, connection, and ds for a
simple, one column (email address) table in Access. I am
trying to do a simple insert of one value. My code:
Dim strEmail As String = Trim
(Me.txtEmail1.Text)
Me.OleDbInsertCommand1.Parameters.Add
("@email", strEmail)
Me.OleDbInsertCommand1.Connection.Open()
Me.OleDbInsertCommand1.ExecuteNonQuery()
Me.OleDbInsertCommand1.Connection.Close()
Generates this error:
OleDBMessage: Parameter ?_1 has no default value.
ErrorCode: -2147217904 Source: Microsoft JET Database
Engine

I have researched and simply cannot figure out what
parameter, where, it is looking for. Please help.

Thank you
Buz
 
¤ Ok, I'm a beginner. I need help.
¤ I've set up an oledbdataadapter, connection, and ds for a
¤ simple, one column (email address) table in Access. I am
¤ trying to do a simple insert of one value. My code:
¤ Dim strEmail As String = Trim
¤ (Me.txtEmail1.Text)
¤ Me.OleDbInsertCommand1.Parameters.Add
¤ ("@Email", strEmail)
¤ Me.OleDbInsertCommand1.Connection.Open()
¤ Me.OleDbInsertCommand1.ExecuteNonQuery()
¤ Me.OleDbInsertCommand1.Connection.Close()
¤ Generates this error:
¤ OleDBMessage: Parameter ?_1 has no default value.
¤ ErrorCode: -2147217904 Source: Microsoft JET Database
¤ Engine
¤
¤ I have researched and simply cannot figure out what
¤ parameter, where, it is looking for. Please help.

You need to specify either a QueryDef or SQL statement. I don't see it in your example.


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
Here is the code:

Me.OleDbInsertCommand1.CommandText = "INSERT INTO emails(email) VALUES (?)"

Me.OleDbInsertCommand1.Connection = Me.cnEmails

Me.OleDbInsertCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("email",
System.Data.OleDb.OleDbType.VarWChar, 50, "email"))

Thank you for the help!



 
If you will look in the first set of code I orginally sent, it is there.
Then I was asked for the other portion of code and sent it. In toto, the
code is as follows:

Me.OleDbInsertCommand1.CommandText = "INSERT INTO emails(email) VALUES (?)"

Me.OleDbInsertCommand1.Connection = Me.cnEmails

Me.OleDbInsertCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("email",
System.Data.OleDb.OleDbType.VarWChar, 50, "email"))

Dim strEmail As String = Trim(Me.txtEmail1.Text)

Me.OleDbInsertCommand1.Parameters.Add("@Email", strEmail)

Me.OleDbInsertCommand1.Connection.Open()

Me.OleDbInsertCommand1.ExecuteNonQuery()

Me.OleDbInsertCommand1.Connection.Close()


Your code below does not set the value for the
OleDbParameter anywhere. That is why it complains that
the parameter has no default value.

Tu-Thach
-----Original Message-----
Here is the code:

Me.OleDbInsertCommand1.CommandText = "INSERT INTO emails (email) VALUES (?)"

Me.OleDbInsertCommand1.Connection = Me.cnEmails

Me.OleDbInsertCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("email",
System.Data.OleDb.OleDbType.VarWChar, 50, "email"))

Thank you for the help!
 
This works for me:

Dim cn As OleDbConnection = New OleDbConnection _
("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents
and Settings\rb\My Documents\db3.mdb")
Dim myInsertQuery As String = "INSERT INTO [Names] ([fname],
[lname]) VALUES ('" & txtFirst.Text & "', '" & txtLast.Text & "')"
Dim catCMD As OleDbCommand = New OleDbCommand(myInsertQuery,
cn)
cn.Open()
Try
catCMD.ExecuteNonQuery()
Catch ex As OleDbException
End Try
cn.Close()


Ok, I'm a beginner. I need help.
I've set up an oledbdataadapter, connection, and ds for a
simple, one column (email address) table in Access. I am
trying to do a simple insert of one value. My code:
Dim strEmail As String = Trim
(Me.txtEmail1.Text)
Me.OleDbInsertCommand1.Parameters.Add
("@email", strEmail)
Me.OleDbInsertCommand1.Connection.Open()
Me.OleDbInsertCommand1.ExecuteNonQuery()
Me.OleDbInsertCommand1.Connection.Close()
Generates this error:
OleDBMessage: Parameter ?_1 has no default value.
ErrorCode: -2147217904 Source: Microsoft JET Database
Engine

I have researched and simply cannot figure out what
parameter, where, it is looking for. Please help.

Thank you
Buz

Please refrain from emailing me so the other
group members can gain from the info as well...
 
¤ Here is the code:
¤
¤ Me.OleDbInsertCommand1.CommandText = "INSERT INTO emails(email) VALUES (?)"
¤
¤ Me.OleDbInsertCommand1.Connection = Me.cnEmails
¤
¤ Me.OleDbInsertCommand1.Parameters.Add(New
¤ System.Data.OleDb.OleDbParameter("email",
¤ System.Data.OleDb.OleDbType.VarWChar, 50, "email"))
¤

The Parameters statement is tripping you up. Based upon the arguments in the above statement you
aren't specifying a value for the email parameter. First argument is the parameter name, then type,
then size, and finally source column. If you add the following it should work:

Me.OleDbInsertCommand1.Parameters("email").Value = strEmail

In addition, your first example should work with the above CommandText SQL statement.


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
Back
Top