Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB 2005 - TableAdaptor Insert to Access Database problem

Status
Not open for further replies.

StellaIndigo

IS-IT--Management
Sep 19, 2002
118
GB
Hi

I have an MS Access 2002 database with a table that I need to insert values into from VB 2005.

I have defined the dataasource and everything works OK except the insert does not insert any data! It doesn't report any error so it looks like it works but the table remains empty.

Here's my insert code:


Dim orderstatusTableAdaptor As New ORDERDataSetTableAdapters.tblOrderStatusTableAdapter
orderstatusTableAdaptor.Insert("hhhh", 999)

The table 'tblOrderStatus' has 2 fields, a string and an integer.

any ideas

Stella

Regards
Stella

There are 10 types of people in the world. Those that understand binary and those that don't.
 
and wich one is the primary key??

and what does the insertcommand look like?(the one it created for you.)



Christiaan Baes
Belgium

"Time for a new sig." - Me
 
The first field (string) has the primary key. I have removed it though, as part of my debugging. Didn't know if that caused an error.

Here is the Insert code

<System.Diagnostics.DebuggerNonUserCodeAttribute(), _
System.ComponentModel.Design.HelpKeywordAttribute("vs.data.TableAdapter"), _
System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Insert, true)> _
Public Overloads Overridable Function Insert(ByVal commission_no As String, ByVal error_number As System.Nullable(Of Short), ByVal status_date As Date) As Integer
If (commission_no Is Nothing) Then
Me.Adapter.InsertCommand.Parameters(0).Value = System.DBNull.Value
Else
Me.Adapter.InsertCommand.Parameters(0).Value = CType(commission_no,String)
End If
If (error_number.HasValue = true) Then
Me.Adapter.InsertCommand.Parameters(1).Value = CType(error_number.Value,Short)
Else
Me.Adapter.InsertCommand.Parameters(1).Value = System.DBNull.Value
End If
Me.Adapter.InsertCommand.Parameters(2).Value = CType(status_date,Date)
Dim previousConnectionState As System.Data.ConnectionState = Me.Adapter.InsertCommand.Connection.State
If ((Me.Adapter.InsertCommand.Connection.State And System.Data.ConnectionState.Open) _
<> System.Data.ConnectionState.Open) Then
Me.Adapter.InsertCommand.Connection.Open
End If
Try
Dim returnValue As Integer = Me.Adapter.InsertCommand.ExecuteNonQuery
Return returnValue
Finally
If (previousConnectionState = System.Data.ConnectionState.Closed) Then
Me.Adapter.InsertCommand.Connection.Close
End If
End Try
End Function

Also, I added another table and made a ref integ link between the 2 to force an error, which it does, so I know the code is connecting to the database ok.


Regards
Stella

There are 10 types of people in the world. Those that understand binary and those that don't.
 
The values ("hhhh", 999) are coded as test data, i got fed up typing values into the input form each time I ran it to test. Normally the function would take values from textbox controls.




Regards
Stella

There are 10 types of people in the world. Those that understand binary and those that don't.
 
for information,

i resolved the problem. although i am using access 2002 the database was in 97 format. once i converted to 2002 format it worked ok.

Stella

Regards
Stella

There are 10 types of people in the world. Those that understand binary and those that don't.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top