Error In Cmd.executenonquery
ASP.NET Community Standup Forums Help Home/ASP.NET Forums/Data Access/DataSource Controls - SqlDataSource, ObjectDataSource, etc/Get error at ExecuteNonQuery() during INSERT data into table Get error at ExecuteNonQuery() during INSERT data into table [Answered]RSS 6 replies Last post Jun 05, 2013 01:23 AM by ying87 ‹ Previous Thread|Next Thread › Print Share Twitter Facebook Email Shortcuts Active Threads Unanswered Threads Unresolved Threads Support Options Advanced Search Reply ying87 Member 1 Points 60 Posts Get error at ExecuteNonQuery() during INSERT data into table Oct 09, 2012 10:51 AM|ying87|LINK Hi, In my program, during insert the data into table, I get this error: 'One or more errors occurred during processing of command. ORA-00936: missing expression'at ExecuteNonQuery(). This is the table I try to insert the data. CREATE TABLE Product ( name varchar2(10) not null, category varchar2(10) not null, facility varchar2(10) not null, quantity numeric(20,0) not null, time_stamp date not null ) Below is the code for insert the data. public static string cs = "Provider=MSDAORA; Data Source=xxx; User ID=xxx; Password=xxx"; public void insertCom() { DataTable dt = new DataTable(); dt = _Ds.Tables[0].Copy(); OleDbConnection con = new OleDbConnection(cs); con.Open(); for (int j = 0; j < dt.Rows.Count; j++) { string name = dt.Rows[j]["name"].ToString(); string category = dt.Rows[j]["category"].ToString(); string facility = dt.Rows[j]["facility"].ToString(); int qty = int.Parse(dt.Rows[j]["quantity"].ToString()); string timestamp = dt.Rows[j]["time_stamp"].ToString(); string insert = "INSERT INTO Product (name, category, facility, quantity, time_stamp)" + " VALUES (@name, @category, @facility, @quantity, to_date('@timestamp', 'mm/dd/yyyy'))"; OleDbCommand cmd = new OleDbCommand(insert, con); cmd.Parameters.Ad
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 site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each https://forums.asp.net/t/1849859.aspx?Get+error+at+ExecuteNonQuery+during+INSERT+data+into+table other. Join them; it only takes a minute: Sign up C# Command.ExecuteNonQuery(); Error Incorrect syntax near 'VALUE' [closed] up vote -2 down vote favorite I've tried a ton of different things with this, I keep getting the same error on my cmd.ExecuteNonQuery(); It throws me this. An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll Additional information: Incorrect http://stackoverflow.com/questions/27058379/c-sharp-command-executenonquery-error-incorrect-syntax-near-value syntax near 'VALUE'. Code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Data; using System.Data.SqlClient; using System.Configuration; namespace Server_Testing { class Program { static void Main(string[] args) { string conString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString; SqlConnection con = new SqlConnection(conString); con.Open(); SqlCommand cmd = new SqlCommand("INSERT INTO Test (Id, Name) VALUE (@Id, @Name)", con); if(con.State == ConnectionState.Open) { //cmd.Parameters.Add(new SqlParameter("@Id", 1)); //cmd.Parameters.Add(new SqlParameter("@Name", "MyName")); //cmd.Parameters.AddWithValue("@Id", 1); //cmd.Parameters.AddWithValue("@Name", SqlDbType.NVarChar).Value = "MyName"; cmd.Parameters.AddWithValue("@Id", 1); cmd.Parameters.AddWithValue("@Name", "Myname"); cmd.ExecuteNonQuery(); } } } } As you can see from the comments, I've tried some things, but non of if works for me, I cant seem to get it right, it must be the SQL string, but that should be fine as well.. Can anyone help me here? c# sql sql-server executenonquery share|improve this question edited Nov 21 '14 at 9:49 marc_s 452k938641029 asked Nov 21 '14 at 9:46 Morten Paaske 414 closed as off-topic by Ryan♦ Jul 12 at 23:01 This question appears to be off-topic. The users who voted to close gave this specific reason:"This que
Tips/Tricks Top Articles Beginner Articles Technical Blogs Posting/Update Guidelines Article Help Forum Article Competition Submit an article or tip Post your Blog http://www.codeproject.com/Questions/327083/how-to-clear-this-error-ExecuteNonQuery-Connection quick answersQ&A Ask a Question View Unanswered Questions View All Questions... http://www.dreamincode.net/forums/topic/276374-cmdexecutenonquery-error-when-updating-to-database/ C# questions Linux questions ASP.NET 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 error in 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 / Suggestions Spam and Abuse Watch features Competitions News The Insider Newsletter The Daily Build Newsletter Newsletter archive Surveys Product Showcase Research Library CodeProject Stuff error in cmd.executenonquery 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 with us About our Advertising Employment Opportunities About Us Ask a Question All Questions All Unanswered FAQ how to clear this error ExecuteNonQuery: Connection property has not been initialized while insert values into database Rate this: Please Sign up or sign in to vote. See more: C# class Connection { public static SqlConnection con = new SqlConnection("Data Source=SYSTEM2\\SQLEXPRESS;Initial Catalog=library;Integrated Security=True"); public static SqlCommand cmd = new SqlCommand(); public static SqlDataReader dr; public static SqlDataAdapter da; public static void Open() { con.Open(); cmd = con.CreateCommand(); cmd.CommandType = System.Data.CommandType.StoredProcedure; } public static void Close() { cmd = null; con.Close(); } private void button1_Click(object sender, EventArgs e) { Connection.con.Open(); Connection.cmd.CommandText = "INSERT_REG"; Connection.cmd.Parameters.AddWithValue("@ID",textBox1.Text); Connection.cmd.Parameters.AddWithValue("@NAME", textBox2.Text); Connection.cmd.Parameters.AddWithValue("@ADDRESS", textBox3.Text); Connection.cmd.Parameters.AddWithValue("@CONTACT", textBox4.Text); Connection.cmd
1 of 1 New Topic/Question Reply 5 Replies - 9956 Views - Last Post: 23 April 2012 - 06:48 AM Rate Topic: #1 vikxit New D.I.C Head Reputation: 1 Posts: 16 Joined: 23-April 12 cmd.ExecuteNonQuery() Error when updating to database Posted 23 April 2012 - 01:10 AM Hello, I'm trying to update a record in MS Access database with the code below. But it says 'Syntax error in UPDATE statement and highlights cmd.ExecuteNonQuery()'. Can anyone help on this? Here's the code: dbconnect.Open() Dim cmd As New OleDb.OleDbCommand cmd.Connection = dbconnect 'chek whether add new or update If Me.txtCustomerID.Tag & "" = "" Then 'add new 'add data to table cmd.CommandText = "INSERT INTO tblCustomer(Customer_ID, First_Name, Last_Name, Gender, Telephone_No, Address, Line_1, Line_2, Email_Add, Registered_Date)" & _ "VALUES(" & Me.txtCustomerID.Text & ",'" & Me.txtFirstName.Text & "','" & Me.txtLastName.Text & "','" & Me.comboGender.Text & "','" & Me.txtTelNo.Text & "','" & Me.txtAddress.Text & "','" & _ Me.txtLine1.Text & "','" & Me.txtLine2.Text & "','" & Me.txtEmailAdd.Text & "',#" & Me.dtpDate.Text & "#)" cmd.ExecuteNonQuery() Else 'update data in table cmd.CommandText = "UPDATE tblCustomer" & _ "SET Customer_ID=" & Me.txtCustomerID.Text & _ ", First_Name'" & Me.txtFirstName.Text & "'" & _ ", Last_Name'" & Me.txtLastName.Text & "'" & _ ", Gender'" & Me.comboGender.Text & "'" & _ ", Telephone_No'" & Me.txtTelNo.Text & "'" & _ ", Address" & Me.txtAddress.Text & "'" & _ ", Line_1'" & Me.txtLine1.Text & "'" & _ ", Line_2'" & Me.txtLine2.Text & "'" & _ ", Email_Add'" & Me.txtEmailAdd.Text & "'" & _ ", Registered_Date'" & Me.dtpDate.Text & "'" & _ "WHERE Customer_ID=" & Me.txtCustomerID.Tag cmd.ExecuteNonQuery() End If dbconnect.Close() Is This A Good Question/Topic? 0 Back to top MultiQuote Quote + Reply Replies To: cmd.ExecuteNonQuery() Error when updating to database #2 CharlieMay This space intentionally left blank Reputation: 1726 Posts: 5,696 Joined: 25-September 09 Re: cmd.ExecuteNonQuery() Error when updating to database Posted 23 April 2012 - 04:25 AM You're missing a bunch of = signs. ", First_Name = '" & Me.txtFirstName.Text & "'" & _ R