Jump to content
  • Advertisement
Sign in to follow this  
zaidgs

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

This topic is 4117 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
connection.Open();

//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);
command.ExecuteNonQuery();

//close the connection
connection.close();
}



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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!