473,411 Members | 2,083 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

how to insert,delete update an access 2000 databSE

Hie people

I have a database named person that has a table called emp and a field by the name Names.Iam using VS 2005 how do I insert,delete and update the database.

this is my code-

Expand|Select|Wrap|Line Numbers
  1. private void button1_Click(object sender, EventArgs e)
  2.         {
  3.             string connetionstring = null;
  4.             string sql = null;
  5.             OleDbConnection cnn;
  6.             OleDbCommand cmd;
  7.  
  8.             connetionstring = "Provider=Microsoft.Jet.Oledb.4.0; Data   source=person.mdb;";
  9.             sql = "insert into emp values(' + textBox1.Text ')";
  10.  
  11.             cnn = new OleDbConnection(connetionstring);
  12.             cmd = new OleDbCommand(sql);
  13.             cmd.Connection = cnn;
  14.  
  15.             cnn.Open();
  16.             try
  17.             {
  18.  
  19.                 cmd.ExecuteNonQuery();
  20.  
  21.                 MessageBox.Show("record inserted");
  22.  
  23.             }
  24.  
  25.             catch(Exception ex)
  26.             {
  27.                 MessageBox.Show("Can not open connection"+ex.ToString());
  28.             }
  29.             cnn.Close();
  30.  
  31.         }
May 20 '10 #1
2 2357
Curtis Rutland
3,256 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1. sql = "insert into emp values(' + textBox1.Text ')";
This most certainly won't work. You are literally using the string "textBox1.Text", not its value, in this string.

Expand|Select|Wrap|Line Numbers
  1. sql = string.Format("insert into emp values('{0}')", textBox1.Text);
This way is better, but still not "good". Parameterized queries are the best.
May 20 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: jason | last post by:
Is there a way - possibly a disconnected rs? - to update the contents of an existing pulldown on a page without having to re-submit the page for the user to see the pulldown populated with an...
16
by: robert | last post by:
been ruminating on the question (mostly in a 390/v7 context) of whether, and if so when, a row update becomes an insert/delete. i assume that there is a threshold on the number of columns of the...
2
by: bala | last post by:
hi access gurus would appreciate if u can give me pointers regarding conversion of ms access 97 application to ms access 2000, like what are the problems to be expected and how to handle it. ...
1
by: Paul BJ | last post by:
I am trying to insert into a table in an Access 2000 DB from a VB6 app using ADO 2.7. I would have thought this should have been really easy but I cannot get it working and I cannot see why. It...
0
by: 4 | last post by:
Insert/Delete/Modify Statement Shortcuts??? Help!! I am working in C# and running an Oracle 9i server. I was just wonering if there is a shortcut way of updating my tables and not have to...
2
by: Rich | last post by:
Hello, I have an oleDBDataAdapter (da1) which gets data from an Access mdb and fills a dataset (ds1) with integer data from "tbl1" in Access. Data displays in textboxes on a form. The...
1
by: eighthman11 | last post by:
Hey everyone: Probably an easy question but here it goes. I have a continous form where you update a quantity order field. When you enter the quantity ordered on a line and tab down to the next...
3
by: ebru | last post by:
about insert/delete/update records in mysql server with asp code how can I insert record in mysql database.. I insert into database but if I leave one text box empty, its give me error how can...
11
ollyb303
by: ollyb303 | last post by:
Hi, I have a problem with a multi-user db in Access 2000. The db is for logging calls to my company and will be used by up to 30 people, though currently around 10 are using it. I have split...
1
Sl1ver
by: Sl1ver | last post by:
i have a Access DB table there is only one row allowed so if no row exist it shouls create one else it should just update it. What should i put in the if statement? if () { ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.