In this example we are using DataTable and noticed that you can't
use two control or operations accessing the table from same form
loacation.
- Insert Command
- Inserting data with connected AdoMode, with a GridView
control.
- DELETE from any ObjectSource will not work, unless
force as shown in the previous document
LINK.
In this document, as we used SqlDatSource to Substitute Delete
method that will delete a row.
- We also tried
protected void GridView1_RowDeleted(object sender,
GridViewDeletedEventArgs e)
protected void SqlDataSource1_Updated(object sender,
SqlDataSourceStatusEventArgs e)
protected void SqlDataSource1_Deleted(object sender,
SqlDataSourceStatusEventArgs e)
protected void GridView2_RowUpdated(object sender,
GridViewUpdatedEventArgs e)
- Using Data Adapter : SqlDataAdapter provides dual mode of
communication with the data base, bridging between DataTable and
Physical datasource..
- public DataTable GetAll()
{
DataTable dt = new DataTable();
try
{
SqlDataAdapter adapter = new SqlDataAdapter("SELECT *
FROM Main2", _connectionString);
adapter.Fill(dt);
strResult += "Data Loaded";
}
catch (Exception error)
{
strResult += "There was an error " + error.Message;
}return dt;
}
- Complete code belongs to this page
(LINK)
|
Step: 1 Add a new site
http://manas6/aspnet.35/mm.AdoConnect4/Default.aspx

|
Step: 2 : We would like to use, an existing Database, as shown in
the image below, and not adding as a folder or local database where
we create a database.mdf file and create a connection link.
Update connection string in Web.config.
<connectionStrings>
<add name="adoCnn" connectionString="Data Source=MANAS6\SQLEXPRESS;Initial
Catalog=adoConnect1;Integrated Security=True" providerName="System.Data.SqlClient;"/>
</connectionStrings>
|
Step: 3: Add a class in App_Code folder,

|
Step: 4 Update the code in adoMain.cs
|
Before you mesh around you may like to make a backup copy your
data using this

Query analyzer replaces wild cat with the field/column name. Note
: Primary Key can't be copied, or inherited therefore if you are
planning to use SqlDataSource you must have enabled primary key


|
Step: 5 Now add data source and grid view controls


Select Get All

UpDate

Insert

|
Step: 6 Now configure GridView with ObjectDataSoyurce


|
Step: 7: Using SqlDataSource

I used Main2 copy (so that I dont corrupt Main table used in
another application mm.AdoConnect3), and did not want to use the
same connection string used in adMain.cs (Web.config).
[Note: When I created SQLDataSource and then configured
GridView2, all the columns were erased out ! ]
<connectionStrings>
<add name="adoCnn" connectionString="Data Source=MANAS6\SQLEXPRESS;Initial
Catalog=adoConnect1;Integrated Security=True"
providerName="System.Data.SqlClient;" />
<add name="adoCnn2" connectionString="Data Source=MANAS6\SQLEXPRESS;Initial
Catalog=adoConnect1;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
Now Let us configure GridView ,


Now we have two strings



|
Step: 9: Now reformat Gridview 2

Properties of Grid View on Default.aspx

|
Step: 10: Now add another Web page, and add a

Add these controls (we have done in the previous
document),
view codes (LINK)

|
Step: 11: Run time
http://manas6/aspnet.35/mm.AdoConnect4/Default.aspx.

Add one row and data


Let us update one field

Note the DataChanged in One but not in the GridView ( obviously
there is no live connection or call back or special trigers used)

Original Data Base/ Table reflects the change.
Now if you click on Edit Button of GridView1, as show below, the
update method will load current data to the GridView1 and GridView
Vise versa.


Also note the results of the evetns like delete or update or
gridview changed

|
Step: 12
|
Step: 13
|
Step: 2
|
Step: 2
|
Step: 2
|
|