Sign in to follow this  

[web] Programatically modifying a database [ASP.NET]

Recommended Posts

How can I insert and update records in a database programmatically?! Having read through MSDN it seems that Parameters are used to populate the update and insert commands with values. It seems like an easy concept although I couldn't get any working code!! I have a class that populates its properties programmatically. Now I want to save those properties in a database for later retrieval. I created a table in an MS Access database that has fields with the same names as the properties I want to save (I am limited to an Access database not an SQL database - if that matters - but this shouldn't make any big differences since they both has similar interface). I created an AccessDataSource bound to that table. So whats the best way to do direct the parameters to collect the values?! Is there any way that is easier and\or more intuitive than parameters?! Please help... Thanks for your effort. PS: I am using Visual Web Developer 2005

Share this post

Link to post
Share on other sites
I don't really like the pre-built controls like the AccessDataSource..but there are many people who do.

The alternative I use to update a table is by doing everything yourself using code..for example to update an access table the code would be something similar to

using System.Data.OleDB;

private void UpdateRecord()

//Create a DB Connection and connect to it
string connectionString = "make your connection string here";
OleDbConnection connection = new OleDbConnection(connectionString);
//Open The Connection

//Make your SQL Query To execute
string sql = "UPDATE TableName SET Row1 = 'ValueIWant' WHERE RowID = 'someKeyOrSomething'";

//Make the command object and run the query
OleDbCommand command = new OleDbCommand(sql, connection);

//close the connection

This was off the top of my head so some things may be wrong...If this wasn't what you wanted at all..just ignore the post and I apologize ;-)...but this is similar to the way I Update or Insert records programmatically...using SQL

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this