Update access file from datagrid

F

facicad

Look my prog. I have combobox where is have all tables names of access
file. The user select one table and the content is show in datagrid. The
user can add, erase or modify some record or row. Until now is ok but went
I want to update access file, VB send me error. Some body can help me


Dim myCnn As New OleDb.OleDbConnection

Dim objDataAdapteur As OleDbDataAdapter

Dim objDataSet As New Data.DataSet

Dim objDataTable As DataTable

----------------------------------------------------------------------------
---------------------------------------------------------------

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

myCnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
& AccessFile & ";"

myCnn.Open()

Dim strSQL As String = "SELECT * FROM [" & TableName & "]"

objDataAdapteur = New OleDb.OleDbDataAdapter(strSQL, myCnn)

Dim objCB As OleDb.OleDbCommandBuilder = New
OleDb.OleDbCommandBuilder(objDataAdapteur)

objDataAdapteur.Fill(objDataSet, TableName)

objDataTable = objDataSet.Tables(TableName)

DataGrid1.SetDataBinding(objDataTable, "")

End Sub

----------------------------------------------------------------------------
--------------------------------------------------------------

'Click on button to copy modify on datagrid in access file

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

objDataAdapteur.Update(objDataSet, TableName)

myCnn.Close()

End Sub
 
H

Herfried K. Wagner [MVP]

C

Cor Ligthert

For data(base) related questions, give this group a try:
<URL:news://news.microsoft.com/microsoft.public.dotnet.framework.adonet>

However when it is about Win32, SQLserver or VB6 feel free to use this
newsgroup.

You than get your answers from Herfried. K. Wagner here.

:-(

Cor
 
C

Cor Ligthert

Hi Faci,

Try it in your program without the conn.open and the conn.close.

Howeverr because it is access and for me prefered to open and close that
only one time, you can open the connection in the load_event of the form and
close it in the close_event of the form.

However try it first with removing those two, the dataadapter opens and
closes it himself when there has no open been done before.

I hope this helps?

Cor
 
F

facicad

I try, but it send me same error.
Take look on VB message send to me to help me :)

One exception unsuport of type 'System.Data.OleDb.OleDbException'
to produce in system.data.dll

It send me notthing else to help me!!!
 
H

Herfried K. Wagner [MVP]

* "Cor Ligthert said:
However when it is about Win32, SQLserver or VB6 feel free to use this
newsgroup.

No!

I give answers on p/invoke here, because 'Declare' is VB.NET syntax, and
p/invoke in general is very VB.NET specific.
 
C

Cor Ligthert

Herfried,
I give answers on p/invoke here, because 'Declare' is VB.NET syntax, and
p/invoke in general is very VB.NET specific.


Do you maybe know what programming language is used beneath it was in the
message from the OP.

Dim A As New X
Dim B As X
Dim C As New X
Dim D As X
Private Sub ComboBox1_SelectedIndexChanged
Dim strSQL As String = "X"
U = New Xy
Dim objCB As X
End Sub

I skipped a little bit to make it easier to read.

You know I have fun pointing you on this, nothing real serious.

:)

Cor
 
C

Cor Ligthert

You can Add this, it should anyway

Try
myCnn.Close()
Catch e as exception
messagebox.show(e.tostring)
End Try

You get than a better idea of the error.
And when you do not understand it than, reply it.


Cor
 
F

facicad

Thank you for help me to find more information about error message.
I put try function not at close connection but for update DataAdapter

The new error message tell me about
Syntax error in UPDATE function, but if I use OleDbCommandBuilder, I think,
is make for me update, suppress and add function not ?
OleDbCommandBuilder


Try

objDataAdapteur.Update(objDataSet, TableName)

Catch ex As Exception

MessageBox.Show(ex.ToString)

End Try
 
C

Cor Ligthert

Hi Faciad,

Can you change these two from place?

objDataAdapteur.Fill(objDataSet, TableName)

Dim objCB As OleDb.OleDbCommandBuilder = New
OleDb.OleDbCommandBuilder(objDataAdapteur)

I hope this helps?

Cor
 
F

facicad

Thank you for help me to find more information about error message.
I put try function not at close connection but for update DataAdapter

The new error message tell me about
Syntax error in UPDATE function, but if I use OleDbCommandBuilder, I think,
is make for me update, suppress and add function not ?
OleDbCommandBuilder


Try

objDataAdapteur.Update(objDataSet, TableName)

Catch ex As Exception

MessageBox.Show(ex.ToString)

End Try
 
C

Cor Ligthert

Hi Facicad,

Did you see my other message as well, I was not seeing direct that your
commandbuilding was done before that the data was readed?

Cor
 
F

facicad

No!! I use outlook express and your previous message is not apparent. I go
on devdex.com an I see ;-)
I built test application with juste the section of datagrid and is work
perfect. But went I integrete in my project, the bug come again. I think
is wend my prog. built table in access, i can't assign primery key and
automatic number for row. Beacause went i built access table manualy, it
work correctly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top