C# database Question?
-
this code is written in C# and the database is microsoft access..... cb= new OleDbCommandBuilder(daSub); DataRow drow = ds.Tables[uname].NewRow(); for (int ctr = 0; ctr < Subj_enroll.Items.Count; ctr++) { String Subj = Subj_enroll.Items[ctr].Text.ToString(); String Section = Subj_enroll.Items[ctr].SubItems[1].Text.... String Units = Subj_enroll.Items[ctr].SubItems[2].Text.... String Day = Subj_enroll.Items[ctr].SubItems[3].Text.... String Time = Subj_enroll.Items[ctr].SubItems[4].Text.... drow["Subject"]=Subj; drow["Units"] = Section; drow["Section"] = Units; drow["Day"] = Day; drow["Time"] = Time; ds.Tables[uname].Rows.Add(drow); daSub.Update(ds, uname); ds.Tables[uname].AcceptChanges(); } MessageBox.Show("Saved!", "Database MSG"); } ..............From listview I put it to string and then to datarow and then insert it to the database.... ...............I get the error "Syntax Error in insert into statement"......... .......hate this error!........ P.S. I'm have checked the variables and they're not null or blank.... 7 minutes ago - 4 days left to answer. Additional Details Tried this too also didn't work: sql = "INSERT INTO " + uname + " (Subject, Units, Section, Day, Time) VALUES (" + Subj + "," + Section + "," + Units + "," + Day + "," + Time + ")"; comm = new OleDbCommand(sql, conn); comm.ExecuteNonQuery();
-
Answer:
your values are all strings so you need to enclose them in single quotes: sql = "INSERT INTO " + uname + " (Subject, Units, Section, Day, Time) VALUES ('" + Subj + "','" + Section + "','" + Units + "','" + Day + "','" + Time + "')"; copy/paste that - hope it works..should work
Healthmaker E at Yahoo! Answers Visit the source
Other answers
your values are all strings so you need to enclose them in single quotes: sql = "INSERT INTO " + uname + " (Subject, Units, Section, Day, Time) VALUES ('" + Subj + "','" + Section + "','" + Units + "','" + Day + "','" + Time + "')"; copy/paste that - hope it works..should work
Anthony
I'm no C# coder, actually I'm a VB coder. But for what I knew, "Syntax Error in insert into statement" means there is an error in your insert statement. What I can suggest is to debug the program, get the insert query, then try to run the query directly to the access database. Or, you can simply put the query here.
4n7JuK
I am not use but this C# tutorial may help you:
Sovandara
I'm no C# coder, actually I'm a VB coder. But for what I knew, "Syntax Error in insert into statement" means there is an error in your insert statement. What I can suggest is to debug the program, get the insert query, then try to run the query directly to the access database. Or, you can simply put the query here.
4n7JuK
I am not use but this C# tutorial may help you:
Sovandara
Related Q & A:
- Does Restore "From database" restore from the most recent backup of the database or the actual live database?Best solution by Database Administrators
- How to Convert a C++ Structure into C# Structure?Best solution by Stack Overflow
- How to sync Sqlite Database with Remote Database?Best solution by Stack Overflow
- What is the difference between C# and C#.NET?Best solution by Stack Overflow
- How to learn C# (moving from C++ to C#?Best solution by stackoverflow.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.