Search This Blog

Mar 10, 2010

RETRIEVING THE VALUES FROM SQL DATABASE BY FORM VIEW

RETRIEVING THE VALUES FROM SQL DATABASE BY FORM VIEW

  • Take the form view on the design page of the default.aspx.
  • On its source code , u need to write the following code under the form view code.             
              


              


              
              
              
              

              
              
              
Note:
  • naina and sneha which is written in the blue color is userdefined . u can write anything in place of it.
  • the pink color text consists of directive:
          # = it is used to retrieve the value at runtime.

         login id & contact id = u can write  any other table name in place of it . basically  this is the table name .
         EVal = it retrieves the particular value from sql database. 

  •  U need to add the namespace in the namespace list given in the above default.aspx.cs page.
           using System.Data.SqlClient;
  • On the page load of the default.aspx.cs , do the following code  :
           SqlConnection a
           SqlDataAdapter b;
           DataSet c;
           a = new SqlConnection("server = . ; uid = sa ; pwd = ans ; database = adventureworks");
           b = new SqlDataAdapter("select ContactID, LoginID from HumanResources.Employee where EmployeeID = "1",a);
           c = new DataSet( );
           b.Fill(c);
           formview1.DataSource = c;
           formview1.DataBind( );

Note:
  • a = is a object for sql connection class and is userdefined , u can write anything in place of it.
  • b = is a object for sql data adapter class.
  • c = is a object for dataset class.
  • . = is represented for using system resources and it will take server name automatically.
  • sa = is a default sql server 2005 id.
  • ans = is a password which u have given at the install time .
  • adventure works = is a database which u have in ur sql server 05. u can take any database which u have made in sql .
  • contactID and login ID= is a columns name is the adventure work database.
  • humanresources.employee = is  a table name having employee column.
  • employeeID = is a column name of the human resources table.