Click here to Skip to main content
16,023,117 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to insert data in MS access

The query execute corectly,everything going in coreect manner but when i open the table it does not contain entered data

the code is

string SaveConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=UI.mdb";
OleDbConnection ConnForSaveTabs = new OleDbConnection(SaveConnString);
string SaveCommand = @" Insert into Tabs (Name,Caption) values('" + txtname.Text + "','" + txtcaption.Text + "') ";
OleDbCommand CommandForSave = new OleDbCommand(SaveCommand, ConnForSaveTabs);
CommandForSave.ExecuteNonQuery();
Posted

Ignoring for a moment how this code allows anyone to erase your database if they want, have you checked the return value of ExecuteNonQuery ? It returns the number of rows changed. Have you run this SQL against your DB directly ? I see no reason for it not to work, but it's always good to check.

Where is your DB stored, just in the local directory ? Do other change operations work ? Might your lack of a path in your data source mean you're actually changing a different DB to the one you think you are ?

In addition, as I've said before, apart from being insecure, code that hard codes connection strings inside the UI layer, and/or builds SQL in the UI layer, is bad code. I assume you're just playing, but you should aim to improve your design skills before expecting anyone to pay for code that you write.
 
Share this answer
 
Hi.sharmarun
Your problem is easy and good
you set a data source=UI.mdb.
Not give a path so first give a path and after set database name
e.g "data source=C:\\Hello\UI.mdb";
I Hope This Help is usefull for you
please send your comment for this answer
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900