473,382 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

What i missing!! please help. Insert query to Acces 2007

this is my query;
Expand|Select|Wrap|Line Numbers
  1. string NPI =                fields.GetValue(0).ToString();
  2.             string EntiType =           fields.GetValue(1).ToString();
  3.             string ProvLastNameLegal =  fields.GetValue(5).ToString();
  4.             string ProvFirsName =       fields.GetValue(6).ToString();
  5.             string ProvMiddName =       fields.GetValue(7).ToString();
  6.             string PromNamePref =       fields.GetValue(8).ToString();
  7.             string ProvNameSuffix =     fields.GetValue(9).ToString();
  8.             string ProvCredenText =     fields.GetValue(10).ToString();
  9.             try
  10.             {
  11.                 string query = "Insert INTO" + TableName + "(NPI, EntityTypeCode, ProviderLastNameLegalName, ProviderFirstName, ProviderMiddleName, ProviderNamePrefixText, ProviderNameSuffixText, ProviderCredentialText)"+
  12.                  "VALUES(@NPI, @EntityTypeCode, @ProviderLastNameLegalName, @ProviderFirstName, @ProviderMiddleName, @ProviderNamePrefixText, @ProviderNameSuffixText, @ProviderCredentialText)";
  13.                 String ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Gabiel\Documents\CMSProv.accdb; Persist Security Info=False";
  14.                 //@"Provider=Microsoft.Jet.4.0;Data Source=F:\CMSNPI\200910122000\CMSProv.mdb;User Id=admin;Password=;"; //ACCESS 2003
  15.                 OleDbConnection cn = new OleDbConnection(ConnectionString);
  16.                 OleDbCommand cmd = new OleDbCommand(query, cn);
  17.                 cmd.Parameters.AddWithValue("@NPI", NPI);
  18.                 cmd.Parameters.AddWithValue("@EntityTypeCode", EntiType);
  19.                 cmd.Parameters.AddWithValue("@ProviderLastNameLegalName)", ProvLastNameLegal);
  20.                 cmd.Parameters.AddWithValue("@ProviderFirstName", ProvFirsName);
  21.                 cmd.Parameters.AddWithValue("@ProviderMiddleName", ProvMiddName);
  22.                 cmd.Parameters.AddWithValue("@ProviderNamePrefixText", PromNamePref);
  23.                 cmd.Parameters.AddWithValue("@ProviderNameSuffixText", ProvNameSuffix);
  24.                 cmd.Parameters.AddWithValue("@ProviderCredentialText", ProvCredenText);
  25.                 cn.Open();
  26.                 cmd.ExecuteNonQuery();
  27.                 cn.Close();
  28.             }
  29.             catch (Exception ex)
  30.             {
  31.                 MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
  32.                 return;
  33.             }
  34.  
the following error ocurrer on this line: cmd.ExecuteNonQuery();

{System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement.

at System.Data.OleDb.OleDbCommand.ExecuteCommandTextE rrorHandling(OleDbHResult hr)
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextF orSingleResult(tagDBPARAMS dbParams, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommandText( Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommand(Comm andBehavior behavior, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteReaderIntern al(CommandBehavior behavior, String method)
at System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
at MCS_ImportTool.MCS_ImportTool.QueryImport(String[] fields, String TableName) in C:\Users\Gabiel\Documents\Visual Studio 2005\Projects\MCS_ImportTool\MCS_ImportTool\Form1. cs:line 242}
Nov 21 '09 #1

✓ answered by ThatThatGuy

Check out this part of the insert statement once again
Expand|Select|Wrap|Line Numbers
  1. "Insert INTO" + TableName + "(NPI, EntityTypeCode, ProviderLastNameLegalName
  2.  
there's no space between the INTO keyword and the table name:::: so that's the error point....

2 1781
ThatThatGuy
449 Expert 256MB
Check out this part of the insert statement once again
Expand|Select|Wrap|Line Numbers
  1. "Insert INTO" + TableName + "(NPI, EntityTypeCode, ProviderLastNameLegalName
  2.  
there's no space between the INTO keyword and the table name:::: so that's the error point....
Nov 21 '09 #2
Thanks i fix that peace of code but the error still theare!!
string query = " Insert INTO " + TableName + " (NPI, EntityTypeCode, ProviderLastNameLegalName, ProviderFirstName, ProviderMiddleName, ProviderNamePrefixText, ProviderNameSuffixText, ProviderCredentialText) "+
" VALUES (@NPI, @EntityTypeCode, @ProviderLastNameLegalName, @ProviderFirstName, @ProviderMiddleName, @ProviderNamePrefixText, @ProviderNameSuffixText, @ProviderCredentialText)";
String ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Gabiel\Documents\CMSProv.accdb; Persist Security Info=False";
Ok i need to tell what the data i'm traying to insert to my access data base is from a .csv file. and each fields look like this ("\" 123467"\""")

thanks again for your helps
Nov 21 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: AMD Desktop | last post by:
Here is the table: CREATE TABLE ( IDENTITY (1, 1) NOT NULL , NOT NULL , NOT NULL , NOT NULL CONSTRAINT DEFAULT (0), NOT NULL , NOT NULL ) ON
2
by: avinash | last post by:
hello myself avinash i am developing on application having vb 6 as front end and sql server 7 as back end. when i use insert query to insert data in table then the date value of that query is...
4
by: dcarson | last post by:
I've read about this error in several other discussions, but still can't seem to pinpoint the problem with my code. Everything seemed to be working fine for some time, but it now tends to bomb out...
8
by: Carl | last post by:
Hi, I hope someone can share some of their professional advice and help me out with my embarissing problem concerning an Access INSERT query. I have never attempted to create a table with...
2
by: sfrvn | last post by:
I am embarrassed to say I cannot make this work. Recently upgraded to Access 2003, but do not know if that part of problem (AKA 'syntax change'). Would someone be kind enough to lead me by the...
8
by: Santy | last post by:
Hello All, I am new to DB2, Currently i am using DB2 version 8.02 personal edition on Windows XP Professional. And Facing problem with rowlock in insert query. I have created a sample database...
3
by: BreckCogdill | last post by:
Hello, I'm trying to modify some code in simple Forum script - adding an ID field to an insert statement. I have added the field to the d/b & now I'm trying to add this new field to the existing...
4
by: thebarefootnation | last post by:
Hi I have the following error message "Syntax Error (missing operator) in query expression" occurring when I am trying to update combo box within a form. My code is: Dim strSQL As String
3
by: Margie | last post by:
Working on my database I use a modified piece of code gotten from thescripts. The code works perfectly except for one thing. When entering data containing the character ' , I get the error: Syntac...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.