sql notes

 datconncet database to web form(aspx)

steps

1.include database library

  SQLSERVER - library sqlclient

  XML - library xml

  ACCESS(excel) - library oledb



How to use library

 using system.data.library;

eg. using system.data.sqlclient;


step 2:

create database object

there are following object is used to create in a database 

a.sqlconnection-representing database location/path


 SYNTAX 

sqlconnection objname;


eg.sqlconnection cn;


b.sqlcommand- representing all query(insert,update,select,delete)


 SYNTAX

sqlcommand objname;


eg.sqlcommand cm;

c.sqldatareader-it used to reading record from database(if we have to used select query then using datareader object)


SYNTAX

 sqldatareader objname;

eg.sqldatareader dr;


NOTE: all object is to be create before the page load


step 3

Break the page reloading process(inside the page load event)


if(!ispostback)

{


}


DATABASE CODING(insert,update,delete,select and all query)

step 1: Open connection

step 2: Apply database command(insert,update,delete,select)

step 3: Execute command 


Note: All types of coding is based on object oriented programming 

All information is stored in a variable 

variable pass to the object


eg. string k ="insert query";

cm=new sqlcommand(k);


eg. string k="delete query";

cm=new sqlcommand(k);


eg. string k="update query";

cm=new sqlcommand(k);


eg. string k="select query";

 cm=new sqlcommand(k);


eg. string k="database loaction";

cn=new sqlconnection(k);



Types of query

1.execute non query(insert,update,delete)

2.execute query(select query)


How to perform insert query 

   1. connection open

   2.command apply 

   3.Execute command 


1. Connection open 

        find out the database location 

database loaction find by @ symbol 


steps 

  •   drag and drop your table name 
  •   select sqldatasource click configure data source, click + symbol and copy the connection string path, and remove the control  


2.command apply

insert into demo values(1,'ramesh','nagpur');

insert into demo values(2,'sita','pune');


id textbox1

name textbox2

city textbox3

insert into demo values (textbox1.text,textbox2.text,textbox3.text);


how to pass control in a query 

  there are some patterns is used to pass control in a query 


  • direct method 
  • parametrised method 


1.direct method 

syntax 

       '"+control name +"','"+control name+"',----n


eg: insert into demo values('"+textbox1.text+"','"+textbox2.text+"','"+textbox3.text+"');


insert update delete = nonexecuted query

select = executed query


Comments

Popular posts from this blog

Basic Query program(insert,update,delete,select)

Data transmission and query string

Detailview(program)