• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 214
  • Last Modified:

Why cant i insert into access database?

i have eightcolumns in my access database. one is an autonum. I want to insert the values from my form into the database but i keep getting an error saying that my insert statement is incorrect. does anyone know what im doing wrong?

OleDbConnection Myconnection = null;
Myconnection = new OleDbConnection (@"Provider=Microsoft.Jet.OLEDB.4.0; User Id=; Password=; Data Source=C:\Database.mdb");
Myconnection.Open();

OleDbCommand cmd = Myconnection.CreateCommand();
cmd.CommandText = "INSERT INTO Users (Name,Surname,DOB,Gender,Smoker,State,Note) VALUES ('" + txtName.Text + "', '" + txtSurname.Text +"', '" + txtDateofBirth.Text +"', '" + rdbGender.SelectedValue +"','" + rdbSmoker.SelectedValue +"','" + DropDownState.SelectedValue +"','" + txtNote.Text +"')";
cmd.ExecuteNonQuery();
Myconnection.Close();
0
DelphiCurious
Asked:
DelphiCurious
  • 5
  • 4
1 Solution
 
arif_eqbalCommented:
OK, put a breakpoint on
cmd.CommandText = "INSERT ....."
check the CommandText value copy it and run it on the backend
you'd get a proper Error saying what exactly is wrong with the Query
0
 
DelphiCuriousAuthor Commented:
i did that, went to access and did a query in sql view but it just says that theirs an error , its not specific
0
 
arif_eqbalCommented:

Can you post the Insert Query generated,
Also what is rdbGender, rdbSmoker   radioButtons ??
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
DelphiCuriousAuthor Commented:
"INSERT INTO Users (Name,Surname,DOB,Gender,Smoker,State,Note) VALUES ('Joe', 'Sampson', '18/05/1982', 'Male','No','Northern Territory','this is the note section')"

yes they are radio buttons
0
 
arif_eqbalCommented:
Hi DelphiCurious
Change the Column Name From "NOTE" to say "NOTES"
Note seems to be some reserved word for Access,
If you run your Query on the Backend, after giving the Error Access highlights the word "Note" that gives you a hint that there's some problem with this word
0
 
DelphiCuriousAuthor Commented:
i changed that and now it comes up with Operation must use an updateable query message. I have looked into this and looks like permissions in my access database but i cant work it out. Sometimes when i open the database it says its read only and other times it doesnt, any suggestions?
0
 
arif_eqbalCommented:
Looks like the Guest account used by IIS for your web Apps does not have proper permissions for this MDB file
Allow "Everyone" to Read/Write to the MDB file by Right Click -> Properties ->Security tab

In case problem persists try out these MS sites for resolution
http://support.microsoft.com/?id=175168
http://support.microsoft.com/?scid=kb;en-us;830977&spid=2514&sid=307
http://support.microsoft.com/default.aspx?scid=kb;en-us;316675

0
 
DelphiCuriousAuthor Commented:
i solved this by right clicking on the database and creating a user everyone and setting that permission to everything. i am giving arif the points as he helped me to find this. thanks
0
 
arif_eqbalCommented:
Thanks
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now