473,396 Members | 1,849 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,396 software developers and data experts.

C# and saving data in access database!

Hi to all ! I have problem with C# and access databasses!

I can't to insert new record in database , ( I mean I made grid view and connect him with a access database and made all things to insert data in column in datagridview and it showing that row is filed with new data but when I restart form in database there is no new record)..

I use for exmpl: same code but with OLEDB;

Expand|Select|Wrap|Line Numbers
  1.  
  2. string connectionString = "Data Source=SERV\\SQLEXP;Initial Catalog=tempdb;Integrated Security=True";
  3. string command = "UPDATE  telefon 
  4. SET prezime="+textBox2.Text+",telefon="+textBox3.Text+" 
  5. WHERE ime ="+textBox1.Text+"";
  6.  
  7. SqlConnection con = new SqlConnection(connectionString);
  8. SqlCommand cmd = new SqlCommand(command, con);
  9.  
  10. con.Open();
  11. cmd.ExecuteNonQuery();
  12. con.Close();
  13. this.telefonTableAdapter.Fill(this.tempdbDataSet.telefon);
  14.  
and this work in SQL but when I use this same code EXCEPT USING SYSTEM.DATA.OLEDB;

it all works well on form it show adding a data to gridview but it not store in database, I was use :
Expand|Select|Wrap|Line Numbers
  1.  this.telefonTableAdapter.Update();
Expand|Select|Wrap|Line Numbers
  1.  this.telefonTableAdapter.Insert();
  2. AcceptChanges();     
but it NOT SAVE DATA TO ACCESS DATABASSES

PLEASE HELP!!!
Feb 15 '07 #1
4 12940
MMcCarthy
14,534 Expert Mod 8TB
Try changing this code ...

Expand|Select|Wrap|Line Numbers
  1.  
  2. string command = "UPDATE  telefon 
  3. SET prezime="+textBox2.Text+",telefon="+textBox3.Text+" 
  4. WHERE ime ="+textBox1.Text+"";
to this ...

Expand|Select|Wrap|Line Numbers
  1.  
  2. string command = "UPDATE  telefon 
  3. SET prezime='" & textBox2.Text & "', telefon='" & textBox3.Text & "'
  4. WHERE ime ='" & textBox1.Text & "'";
  5.  
The single quotes are because Access requires single quotes for text inserts. The ampersand becuase that is what would normally be used but if you feel C# syntax requires the + sign instead then put it back.
Feb 16 '07 #2
thanx! for help I will tray it !
Feb 16 '07 #3
Tnx mmccarthy that is fine now , but ????????


I have this code and it's work on gridview it showing inserted values but it do not save changes in database !!!!

countRow++;
string str;
con.Open();
str = "insert into tele(ime,broj) values('"+textBox1.Text+ "','"+textBox2.Text+ "')";

DataRow dRow;
DataTable dTable = db1DataSet.tele;
dRow = dTable.NewRow();
dRow[1] = textBox1.Text;

if(textBox2.Text!="")
dRow[2] = textBox2.Text;
dTable.Rows.Add(dRow);

DataTable tab1 = db1DataSet.tele.GetChanges();

ole.Update(tab1);
db1DataSet.tele.AcceptChanges();



PLEASE HELP I WAS TRYING A LOT OF THINGS AND EVEN NOW I CAN' T TO SAVE DATA IN ACCESS DATABASE!!
Feb 18 '07 #4
MMcCarthy
14,534 Expert Mod 8TB
string str;
con.Open();
str = "insert into tele(ime,broj) values('"+textBox1.Text+ "','"+textBox2.Text+ "')";
I can only help with the Access side of things. However, one this seems clear. You have put the INSERT statement into a string but you never execute it. Depending on how you connected to the database this would require something like.

Expand|Select|Wrap|Line Numbers
  1. con.execute str
Mayr
Feb 18 '07 #5

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

Similar topics

13
by: Stuart McGraw | last post by:
I haven't been able to figure this out and would appreciate some help... I have two tables, both with autonumber primary keys, and linked in a conventional master-child relationship. I've...
2
by: manning_news | last post by:
Has anyone had a problem with Access 2003 not saving their coding? I've been using 2003 for a couple of months now and just this week noticed that some coding I'd done for a database was not there...
5
by: Mark | last post by:
I have a VB 6 program that I have saved an audio file to using DAO and the appendchunk as is shown at http://support.microsoft.com/kb/103257/EN-US/. ; I have it working fine in that app (it saves...
4
by: Pedro Leite | last post by:
Good Afternoon. the code below is properly retreiving binary data from a database and saving it. but instead of saving at client machine is saving at the server machine. what is wrong with my...
2
by: chiefsitebuilder | last post by:
I have a question about saving an MS Access program to CD and verifyng that the program works after being saved. Here is my situation, I have a person who developed an application for me using...
3
by: Nathan Guill | last post by:
I have an interface that works with an Access back-end. I would like to store and/or load user defined query strings per each user (i.e. no user can access another's queries). The idea I had was...
4
by: SilentThunderer | last post by:
Hey folks, Let me start out by letting you know what I'm working with. I'm building an application in VB 2005 that is basically a userform that employees can use to "Clock in". The form...
1
by: nmrpa91290 | last post by:
I have a vb 2005 program that I am writing. It is just a form with a datagridview, textbox, and import command button. The code looks like this: Private Sub Form1_Load(ByVal sender As...
0
by: madhu raju | last post by:
iam saving the data into Ms-Access database using Vb.net Application In that application iam using Data grid view to save the data into the database Here in the below code iam saving the name of...
18
by: Marilyth | last post by:
I am using Windows XP and Access 2003. I have searched through my HUGE book & the questions here, and found some items that "might" help, but unsure still. I am still getting versed on Access. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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,...

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.