C# Syntax Error In Create Table Statement
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this syntax error in create table statement access 2013 site About Us Learn more about Stack Overflow the company Business Learn more syntax error in create table statement access 2010 about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x syntax error in create table statement access 2007 Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up CREATE TABLE c# syntax error in update statement syntax error using C# up vote 1 down vote favorite The SQL for creating Access table shows error: string sql = "CREATE TABLE [" + textBox1.Text + "]([S.NO] INTEGER PRIMARY KEY AUTOINCREMENT, [Entry Date] DATETIME)"; OleDbCommand cmd = new OleDbCommand(sql, conn); cmd.ExecuteNonQuery(); c# sql ms-access ado.net share|improve this question edited Dec 25 '14 at 6:31 asked Dec 25 '14 at 6:09 Harshan01 3410 1
C# Syntax Error In Insert Into Statement
What is the error? BTW try removing the dot in the column name. –shree.pat18 Dec 25 '14 at 6:10 Visual Studio shows syntax error in CREATE STATEMENT. That's it. No brief explanation. –Harshan01 Dec 25 '14 at 6:12 No. Didn't work. Same error. –Harshan01 Dec 25 '14 at 6:14 As it turns out this question has nothing to do with C#. –t3chb0t Dec 25 '14 at 9:05 add a comment| 1 Answer 1 active oldest votes up vote 2 down vote accepted Access considers INTEGER and AUTOINCREMENT to be two different data types. Don't declare your field as both. Also Access complained when I requested S.NO as a field name. In order to get the statement to work I substituted an underscore for the dot: CREATE TABLE [tblHarshan01]([S_NO] AUTOINCREMENT PRIMARY KEY, [Entry Date] DATETIME) share|improve this answer answered Dec 25 '14 at 6:46 HansUp 79.1k114371 1 It worked correctly! –Harshan01 Dec 25 '14 at 6:51 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email
.NET Framework > Visual C# Question 0 Sign in to vote OleDbConnection Connection = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Environment.CurrentDirectory + "\\MainClientDataFile.mdb;Persist Security Info=False;"); OleDbCommand Command = new OleDbCommand("CREATE TABLE " + customerNameBox.Text + " ( CustomerName CHAR(30) , MaintenanceCategory CHAR(30) , DateCommencing VARCHAR(20) , DateExpiring VARCHAR(20) , VisitFreq CHAR(10) , ContactName VARCHAR(40) , CustomerNumber VARCHAR(10) , ContactMail VARCHAR(30) , ContactNumber VARCHAR(14) , Device CHAR(20) , Manufacturer VARCHAR(17) , Model VARCHAR(20) )", Connection); Connection.Open(); http://stackoverflow.com/questions/27644671/create-table-syntax-error-using-c-sharp Command.ExecuteNonQuery(); i keep getting this error An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll Additional information: Syntax error in CREATE TABLE statement. If my Question or Comment Helped in anyway, markup as helpful or as answer as the case may be Monday, July 22, 2013 2:21 PM Reply | Quote Answers 1 Sign in to https://social.msdn.microsoft.com/Forums/vstudio/en-US/cd9623c4-a5fc-4255-a9f9-6b3e7f6c8b74/c-oledb-create-table-syntax-error?forum=csharpgeneral vote Hi, if the text in customerNameBox contains any whitespace or special characters the table name must be enclosed in square brackets: "CREATE TABLE [" + customerNameBox.Text + "] ( ..." But as a table can store multiples customers, there is no need to create a table for each customer. Regarding the previous thread: The table must have a primary key to be updatable (for example CustomerName). See Fundamental Microsoft Jet SQL for Access 2000 for syntax examples. Regards, Elmar Marked as answer by BolorunduroWB Thursday, July 25, 2013 7:50 AM Monday, July 22, 2013 3:40 PM Reply | Quote All replies 1 Sign in to vote Hi, what value has the customerName.Text property ?Hannes If you have got questions about this, just ask. In a perfect world, users would never enter data in the wrong form, files they choose to open would always exist and code would never have bugs. My Forum Threads
Monday, July 22, 2013 2:27 PM Reply | Quote 1 Sign in tTips/Tricks Top Articles Beginner Articles Technical Blogs Posting/Update Guidelines Article Help Forum Article Competition Submit an article or tip Post your Blog quick answersQ&A Ask a Question View Unanswered Questions View All Questions... C# questions Linux questions ASP.NET http://www.codeproject.com/Questions/356351/syntax-error-in-create-table-command-with-variable questions SQL questions VB.NET questions discussionsforums All Message Boards... Application Lifecycle> Running a Business Sales / Marketing Collaboration / Beta Testing Work Issues Design and Architecture ASP.NET JavaScript C / C++ / MFC> ATL / WTL / STL Managed C++/CLI C# Free Tools Objective-C and Swift Database Hardware & Devices> System Admin Hosting and Servers Java .NET Framework Android iOS Mobile SharePoint Silverlight / WPF Visual Basic Web Development Site Bugs / syntax error Suggestions Spam and Abuse Watch features Competitions News The Insider Newsletter The Daily Build Newsletter Newsletter archive Surveys Product Showcase Research Library CodeProject Stuff communitylounge Who's Who Most Valuable Professionals The Lounge The Insider News The Weird & The Wonderful The Soapbox Press Releases Non-English Language > General Indian Topics General Chinese Topics help What is 'CodeProject'? General FAQ Ask a Question Bugs and Suggestions Article Help Forum Site Map Advertise syntax error in with us About our Advertising Employment Opportunities About Us Ask a Question All Questions All Unanswered FAQ syntax error in create table command with variable tablename in c# Rate this: Please Sign up or sign in to vote. See more: C# Access Hello, I have to execute various sql queries but my table name is stored in a variable. I am having problem in create table command. I tried 2 different methods,but both are showing syntax error. Here, con is oledbconnection. ninp_tab_name and nout_tab_name are variable names, Input and Output are tables whose schema I want to copy. code1: string new_intb_comm = "CREATE TABLE"+ninp_tab_name+""+"AS SELECT * FROM Input WHERE 1=2"; OleDbCommand cmn = new OleDbCommand(new_intb_comm, con); cmn.ExecuteNonQuery(); code 2: string new_outb_comm = "CREATE TABLE @out_table AS SELECT * FROM Output WHERE 1=2"; OleDbCommand cmo = new OleDbCommand(new_outb_comm, con); cmo.Parameters.AddWithValue("@out_table", nout_tab_name); cmo.ExecuteNonQuery(); Please help asap. Posted 28-Mar-12 13:18pm Member 8722300146 Updated 28-Mar-12 13:25pm RaisKazi34.4K v2 Add a Solution Comments Wes Aday 28-Mar-12 19:55pm And what was wrong with the answer that you already got? Member 8722300 28-Mar-12 21:07pm both of these queries shows syntax error :( If even one of them runs successfully, I can complete my work Wes Aday 28-Mar-12 21:08pm You are getting the syntax errors