I want to be able to edit a table in a SQL server database using c#.
Can someone please show me a very simple tutorial on connecting to the DB and editing data in a table.
Thank you so much.
I want to be able to edit a table in a SQL server database using c#.
Can someone please show me a very simple tutorial on connecting to the DB and editing data in a table.
Thank you so much.
First step is to create a connection. connection needs a connection string. you can create your connection strings with a
SqlConnectionStringBuilder
.Then use that connection string to create your connection like so:
Then, so simple you can use
AddNew()
method in the binding source to Add new record and then save it with update method of your adapter:Use this command to delete a record:
The best way is to add a
DataSet
fromProject->Add New Item
menu and follow the wizard...Have a read of the MSDN tutorial on Creating Data Applications. You may be able to clarify your question, or find the answers you need.
There is info on editing the data in the app but you have to get connected and load it into your app first.
The only reason to do this in C# is if you want to automate it somehow or create an interface for non-technical users to interact with the database. You can use a GridView control with an SQL datasource to manipulate the data.
@kevin: if he's just learning, I think its probably simpler to have him use SQLCommand object (or SQLDataAdapter).
Assuming you're using Visual Studio as your IDE you could just use LINQ to SQL. It's a pretty simple way to interact with your database and it should be pretty quick to get going.
Using LINQ to SQL is a pretty simple walk through in getting it up and running.