Re: OleDbCommandBuilder insert query will not work? dataset to Access

Tech-Archive recommends: Fix windows errors by optimizing your registry



On Feb 28, 9:22 pm, gibbonas <gibbo...@xxxxxxxxxxxxxxxxxxxxxxxxx>
wrote:
I am trying to take a very strangely delimited text file and put it into
access. So far I was able to get the text file into a dataset and figured
from there I could get it into access. I am trying to use the code below but
the insert query just will not work. I am working with a blank access
database and I am able to get the table and the field names in the
database(with a primary key). I just cannot get the rest of the data. I get
an error that there is incorrect syntax in the insert query. Can someone
please help! I've been all over the site reading a buch of different things
and tried to just write inserts for each row but cannot get that to work
either.
Thank you!

DataSet result = new DataSet();
...get delimited file into dataset...

OleDbConnection DB = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=c:\\Conversions\\" + agencyid + "\\" + agencyid + ".mdb");

OleDbDataAdapter DataAdapter = new OleDbDataAdapter();
DataAdapter.SelectCommand = new OleDbCommand("SELECT * FROM " + TableName,
DB);
OleDbCommandBuilder CmdBuilder = new OleDbCommandBuilder(DataAdapter);
DB.Open();
DataAdapter.FillSchema(result, SchemaType.Source, TableName);
DataAdapter.InsertCommand = CmdBuilder.GetInsertCommand();
//I added the line above because the insert query did not show in the data
adapter.
//It now has: insert into tablename(fieldname1,fieldname2...) Values
(?,?,?...)

DataAdapter.Fill(result, TableName);
DataAdapter.Update(result, TableName);//Fails here on the insert query
DB.Close();

You can using try catch to see what exception throw.
Or just execute the same insert statement in the sql query analyse
Good luck.
.



Relevant Pages

  • OleDbCommandBuilder insert query will not work? dataset to Access
    ... database and I am able to get the table and the field names in the ... database(with a primary key). ... an error that there is incorrect syntax in the insert query. ...
    (microsoft.public.data.ado)
  • Re: Problem with Access concatenate query
    ... records in the final query. ... You probably need to INNER JOIN the tables, although on what column, I am not sure. ... PriceID -- Primary Key ... ItemID --- Foreign Key ...
    (microsoft.public.access.queries)
  • RE: Processing thousands of records
    ... Jerry Whittle, Microsoft Access MVP ... Access automatically creates an index for primary key fields. ... that the query is working faster, you don't need the 1stVisit02 query. ... where do I read about fundamental indexing and normalization? ...
    (microsoft.public.access.queries)
  • RE: Processing thousands of records
    ... Access automatically creates an index for primary key fields. ... that the query is working faster, you don't need the 1stVisit02 query. ... Jerry Whittle, Microsoft Access MVP ... where do I read about fundamental indexing and normalization? ...
    (microsoft.public.access.queries)
  • Re: Determining if a form has a table or query recordset source
    ... how to obtain the primary key of a query? ... the generic answer is: "who says any query has one?". ... > set for insertion into an audit trail table, ... > Dim audID As Long ...
    (microsoft.public.access.security)