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

Started by
1 comment, last by zaidgs 16 years, 10 months ago
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
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 itstring connectionString = "make your connection string here";OleDbConnection connection = new OleDbConnection(connectionString);//Open The Connectionconnection.Open();//Make your SQL Query To executestring sql = "UPDATE TableName SET Row1 = 'ValueIWant' WHERE RowID = 'someKeyOrSomething'";//Make the command object and run the queryOleDbCommand command = new OleDbCommand(sql, connection);command.ExecuteNonQuery();//close the connectionconnection.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
Thank you man, I adapted this code to my needs and it works. :)

This topic is closed to new replies.

Advertisement