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

How to do an update from C# to Accdb

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.Data;
  8. using System.Data.OleDb;
  9.  
  10. public partial class _Default : System.Web.UI.Page
  11. {
  12.     protected void Page_Load(object sender, EventArgs e)
  13.     {
  14.     }
  15.     protected void btnCancel_Click(object sender, EventArgs e)
  16.     {
  17.  
  18.     }
  19.     protected void btnUpdate_Click(object sender, EventArgs e)
  20.     {
  21.         string conString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" + Server.MapPath("MainData.accdb") + "'; Persist Security Info=False;";
  22.         OleDbConnection conn = new OleDbConnection(conString);
  23.  
  24.         DataSet ds = new DataSet();
  25.         OleDbDataAdapter Update = new OleDbDataAdapter("Update Clients SET  address = '" + txtadd.Text + "', maritalStatus = '" + maritalstatus.ControlStyleCreated + "', homeContact = '" + txthome.Text + "', mobile = '" + txtmob.Text + "', office = '" + txtoff.Text + "' WHERE firstName = '" + txtfName.Text + "', ", conn);
  26.         conn.Open();
  27.       int n = Update.Fill(ds);
  28.         conn.Close();
  29.  
  30.     }
  31.     //Validate particulaars to check if updated.
  32.  
  33.              if (  n > 0)
  34. {
  35.         MessageBox.Show("Record Updated");
  36.         loaddata();
  37. }
  38.         else
  39.         MessageBox.Show("Update Failed");
  40. }
  41.  
  42. }
Mar 19 '13 #1
3 3856
r035198x
13,262 8TB
So what's the problem? Does it not compile? Does it throw an exception?

P.S Use code tags when posting code.
Mar 19 '13 #2
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.Data;
  8. using System.Data.OleDb;
  9.  
  10. public partial class _Default : System.Web.UI.Page
  11. {
  12.     protected void Page_Load(object sender, EventArgs e)
  13.     {
  14.     }
  15.     protected void btnCancel_Click(object sender, EventArgs e)
  16.     {
  17.  
  18.     }
  19.     protected void btnUpdate_Click(object sender, EventArgs e)
  20.     {
  21.         string conString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" + Server.MapPath("MainData.accdb") + "'; Persist Security Info=False;";
  22.         OleDbConnection conn = new OleDbConnection(conString);
  23.  
  24.         DataSet ds = new DataSet();
  25.         OleDbDataAdapter Update = new OleDbDataAdapter("Update Clients SET  address = '" + txtadd.Text + "', maritalStatus = '" + maritalstatus.ControlStyleCreated + "', homeContact = '" + txthome.Text + "', mobile = '" + txtmob.Text + "', office = '" + txtoff.Text + "' WHERE firstName = '" + txtfName.Text + "', ", conn);
  26.         conn.Open();
  27.       int n = Update.Fill(ds);
  28.         conn.Close();
  29.  
  30.     }
  31.     //Validate particulaars to check if updated.
  32.  
  33.              if (  n > 0)
  34. {
  35.         MessageBox.Show("Record Updated");
  36.         loaddata();
  37. }
  38.         else
  39.         MessageBox.Show("Update Failed");
  40. }
  41.  
  42. }
  43.  
Mar 20 '13 #3
r035198x
13,262 8TB
Don't build your parameters by concatenating strings like that.
Read http://bytes.com/topic/net/insights/...e-your-program to see how to use Parameters
Mar 20 '13 #4

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

Similar topics

1
by: Chris | last post by:
How do you stop a user from double-clicking on .ACCDB file of 2007 and being able to see the tables' and queries structure ? If the solution is the database password, then database cannot open...
3
by: Robert | last post by:
I understand that new features would not be available but is there any way I could open an accdb database in Access 2003? Robert
4
by: ARC | last post by:
I have another question. With Access 2007, as I understand it, you only need to use the .accdb if you are using features such as memo notes history, or the multiple selections for a given key id. ...
0
by: brendanmcdonagh | last post by:
Hi all, I have been working with java on a database program that connects via jdbc odbc access driver on my xp desktop. It is working fine but I'm installing it on 3 pc's tomorrow so testing it...
11
by: wassimdaccache | last post by:
Dear friends I am working on access 2007 sp2. I do have a database(accdb) i converted it to accde. While I am opening the converted database the VBA code is not working. For example...
4
by: MrDeej | last post by:
Anybody now if i can do this programtically? My challenge is that i have a maybe 10 distributions a week with updates and changes which i now have found the accde format to be of good use. I also...
18
by: johnbe | last post by:
I'm trying to find a way to pick up the values entered into the description box of a Forms property in vba. By that I mean the property when a form is right clicked and property selected and the...
1
by: jypw | last post by:
Hi! I have 2 accdb files. I need to create a recordset that will include rows comming from 2 tables that are in 2 different accdb file. Like: select a.no, a.name, a.address, b.total from...
3
by: bullfrog83 | last post by:
I have an .accdb that is linked to a sql server db. I can see the sql db tables in the Navigation Pane. However, I have views, stored procedures and functions on the sql server that I want to link to...
4
by: Jesse Jones | last post by:
I am using a microsoft access 2007 database. We recently updated our computers to office 2010, but have not update the actual database on the server. I have up to fifty people accessing the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.