Machine Test * DATABASE CONNECTIVITY IN WEBFORM *
* DATABASE CONNECTIVITY IN WEBFORM *
1 ) Include database library
a ) SQL Server -- SQLCLIENT
b ) Exel / Access -- OLEDB
c ) XML -- XML
Step 1 :- open dotnet -- file -- new website -- Add new page -- Default.aspx
Q ) How to connect database in dotnet
Step 2 :- server explorer -- right click on Data Connection -- add connection -- Data Source(Microsoft SQL Server (SqlClient)) -- write your Server name ( .\SQLEXPRESS -- select or enterDataBase Name ( VNIT ) -- Test Coonection ( test connection succed) -- ok .
Check where your data connection :- server explorer [ > ]
Compulsary Step for Database Handling
1) Using Library
using System.Data.SqlClient;
2) SqlConnection cn ; // read only connection code
SqlCommand cm ; // read only query
SqlDataReader dr ; // read only data
3) page Load
{
if (!IsPostBack)
{
}
}
Q ) How to Find Database Connection Location and use connection code
Step :- Design-- dataconnection -- table -- Drag table in design -- [ > ] -- select Configure Data Source -- [ + ] -- copy connection code -- and paste on string path ="connection code paste here"
* @ is a database finder
* then use connnection code before @ use it compulsary
ex :- string path = @"Data Source=.\SQLEXPRESS;Initial Catalog=vnit;Integrated Security=True";
cn=new sqlconnection(path) ;
cn.open( ) ;
Types of query
1 ) Non Query :- nonquery refleting the table (INSERT,UPDATE,DELETE)
2 ) EXECUTE READER :- only reading record ( SELECT )
* Parameter Query accepting all types of record.
Q ) How to use Parameter Query
String k = " Insert into Demobb(name,city,mobile)values(@name1,@city1,@mobile1)"
cm=new sqlcommand(k,cn );
cm.parameter.addwithvalue("name1",txtname.text); // pass parameter
cm.parameter.addwithvalue("city1",txtcity.text);
cm.parameter.addwithvalue("mobile1",txtmobile.text);
cm.executenonquery( );
Comments
Post a Comment