Click to See Complete Forum and Search --> : 2 beginner questions


mce
March 18th, 2008, 03:12 AM
hi,

beginner questions..

1)
i am binding a datagrid view to a sql database. How can i make it such a way that if i change the data in the grid view, the same data will get updated into the database?

2)if i want to update a particular field in my sql database, how to do it in csharp? i manage to write codes as below only, after much searching in the internet.

SqlConnection myConnection = new SqlConnection("Data Source=(local); Trusted_Connection=yes");
SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter("select * from Table1", myConnection);

However,,,

NOTE: When i add a datagridview and bind it to my database, visual studio (2008) automatically created the following for me.

table1TableAdapter
table1BindingSource
testDataSet

I have one table in my DB. I just lost on how to make use of this to update my DB. I believe it is possible for me to use the above objects to update individual field in my DB?

nelo
March 18th, 2008, 03:27 AM
Hi,

Are you using a version of Visual Studio? If you are I assume that you've setup a data data source (most likely a SqlDataSource). You can configure that data source with the SQL statements or stored procedures that should executed for updates. Have you done that?

There are different ways of doing things in the .NET framework but at the end of the day you must use some core classes.
SqlConnection
SqlCommand
If you want to read data you can use SqlDataReader or SqlDataAdapter as you've found in an example. I would really advise recommend that you look at MSDN first. It has everything you would need. Search on the internet after you've looked at MSDN.

mce
March 18th, 2008, 03:53 AM
assuming i have filled my dataset from the datasource, let's call it testDataSet, how do i reach an individual cell/field in the table so that i can modify and save it?

cjard
March 18th, 2008, 05:13 AM
Read the DataWalkthrough 2.0 (DW2) link in my signature, section on creating a simple data app