Hi.
I want to give to u some basic knowledge about Data Access in .net.
First of all if you want to make a connecition from database then ,
1.Open Web.Config file which is placed in your project.
2.then make connecition string like that,
You will see there a tag something like that:
<connectionString />ok,now change it .
<connectionString>
<add name="Connecitonstr ingname" connectinString= "Data Source=yourserverna me/sqlexpress; Initial Catalog=Yourdatabas ename;Integrated Security=true" Providername= "System.Data. SqlClient"></ connectionString>
3.Now you have made a connection string named "ConnectinStringnam e" , you will use it to connect database
There are two ways to Connect:
1.Connect through DataGrid,Detail, Form View.
2.Make Custom inserting or retrieving
1.Connect Through DataGrid:
its a simple method just drag and drop data grid view from tool bar and right click on it and chose new data source ,make connection through wizard , its very easy ,
2. Make Custom Retrieving :
Add namespace :
using System.Data. SqlClient;
after that now on event handler
for example you want to run you code on form load then
Protected Void Page_Load(object sender Event Args e)
{
Sqlconnection con = new SqlConnection( ConfigurationMan ager.ConnectionS tring["Yourconec tionstringname" ].ConnectionStri ng);
SqlCommand com = new Sqlcommand(" select * from tablename",con) ;
com.CommandType= CommandType. text;
con.open();
Sqldatareader dr = com.ExecuteReader( );
while (dr.read())
{
label1.Text = dr["Columnname" ].ToString( );
}
dr.close();
con.close();
}
Study this code is retrieving the data from database using data reader and print the text from columname to label1 , it will display on the screen ,
Regards..