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.

        


                
               


Mar 9, 2010

TO ENABLE THE SQL SERVER MODE IN ASP.NET


  • Locate the Aspnet_regsql.exe tool,which is usually resides in the following folder:
           Systemroot\Microsoft.Net\Framework\Versionnumber

Note:
 if u are not able to find  this location .. do the following :

  • go to the windows folder which resides in the Local C drive in My Computer . 
  • open the windows folder , there will be a folder named Microsoft.Net .
  • open the folder named Framework .
  • open the framework folder, there will be a folder named v2.0.50727 .
  • open the same to  find out the Aspnet_regsql.exe. 
  • double click on the same.
  • here the set up is . double click on the same to install it.
  • and thats the location given above in blue format.

  • Run the tool .the following example installs the database on a server called MySqlServer..
        Aspnet_regsql -S MySqlServer -E -ssadd -sstype p

-S ->>> specifies the name off the computer on which SQL Server data store is to be installed.
-E ->>> Facilitates authentication using credentials of the currently logged on user.
 p ->>> it is used for specifying the password for sql server ,with -U option.

  • Once the databes has been installed , you must configure your application to use it. this is done in the following way :
  • In the visual , open the Web.config file 
  • Add the following markup within the tags:
         sqlConnectionString = "Integrated Security = SSPI"; data source = MySqlServer ;" />
 
whereas,

>>Integrated security = it is used to determine whether or not the connection needs to be a secure connection.when false, the user id and password are specified in the connection. when true, the current windows account credentials are use for authentication.Recognised values are true ,false,yes,no ,and ,SSPI (which is equivalent to true).

>>SSPI = security support  provider interface.Different applications have different security requirements for identifying and authenticating users in addition to encrypting data. For example, internet explorer mobile requires server certificate authentication and no client certificate authentication , whereas inbox attachments and infrared downloads require server certificate authentication by default. To support these applications and achieve network authentication , the Security Support Provider Interface(SSPI) allows applications to access DLL's called Security Support Providers(SSPs) - that provide common authentication protocols.




Mar 5, 2010

Generating system exception in asp.net

CODE FOR GENERATING SYSTEM EXCEPTION IN ASP.NET


FOLLOWING STEPS U NEED TO FOLLOW :
  • Open the vs 05.
  • Now,create new website.this will open the default page.
  • Add a textbox and button on the same.
button1_click(object sender eventargs e)
{
if(TextBox1.Text.Length == 0)
{
throw new SystemException();
or u can write :
throw new ArgumentNullException();
}  
  • Add new web form by right clicking on the solution explorer on the url of the web application.
  • Add a label on the same.
  • Now do the following code on the page load of the label click:



if(Page.PreviousPage != null)
{
TextBox t = (TextBox)Page.PreviousPage.FindControl("TextBox1");
if(t != null)
{
Label1.Text = t.Text;
}
}
  • Now add the attribute on the source window of web form 2 in the label part:
PostBackUrl = "Default.aspx"
  • Now add the directive after the page directive in the source window of the default2.aspx :
<@PreviousPageType VirtualPath = "~/Default.aspx">

Mar 4, 2010

Difference between html server controls and web server controls







Difference between html server controls and web server controls


html server controls

these are the HTML elements exposed to the server so as u can program them by writing this attribute in the source window by writing , runat = "server" which makes the html elements work as a html server controls.

additionally,if u write
tags which is used for paragraph, this tag will act as a static text that is passed through to the browser , if u write this tag in a server - side code.


u know there is difference between html elements and html server controls>>>>

u can make the html elements to work as a html server controls by simple conversion
you expose the html controls as html server controls by writing runat="server" attribute in the source code window .

what is the need to add this attribute?

this attribute tells the ASP.NET page framework that it should create an instance of the control during parsing for use during server - side processing.


FEATURES OF HTML SERVER CONTROLS:
  • Data binding for one or more properties of the control.
  • ability to handle events in client script.
  • Automatic maintenance of the control's state. if the form makes a roundtrip to the server, the values that the users entered into HTML server controls are automatically maintained when the page is sent back to the browser.
  • An object model that you can program against on the server.Each server control exposes properties that allow you to manipulate the HTML attributes programmatically in server code.
  • A set of events for which you can write event handlers in much the same way that you would in a client-based form . However, the event is handled in server - side code.



Web server controls


these are the controls designed differently from HTML controls with complex behavior by simply dragging from the tool box.

these controls include traditional form controls , such as buttons and text boxes, in addition to complex controls such as tables, calenders , and tree views.

FEATURES OF WEB SERVER CONTROLS:

  • Rich model object that provides type - safe programming capabilities.
  • Automatic browser detection .create appropriate output for both basic and rich browser.
  • Ability to define consistence appearances for the controls by using templates.
  • Post Back event and auto post back event causes immediate posting to the server or is instead cached and raised when the form is submitted.
  • ability to pass events from a nested control, such as button in a table, to the container control.

>> see this pattern to understand about the object model



when the web forms page runs, ASP.NET renders the web server control on the page by using appropriate HTML , which often depends not only on the browser type, but also on the settings that you have made for the control. for example , a text box control might render as an tag or a



MAIN DIFFERENCE BETWEEN HTML SERVER CONTROLS AND WEB SERVER CONTROLS WHICH MAKES THEM UNIQUE FROM EACH OTHER

  In html server controls,the object model for HTML server controls maps closely to that of the corresponding elements.for example,HTML server controls as properties .
                    
                                   whereas web server controls do not map one to one to HTML server controls.instead they are abstract controls,in which the HTML rendered can be quite different from the model that you program against. for example, RADIOBUTTONLIST web server control might be rendered in a table or as inline text with other HTML .
              

the object model for html server controls maps closely to that of corresponding elements. for example, HTML attributes are exposed in HTML server controls as properties. whereas, web server controls do not map one -to -one to HTML server controls.Instead, they are abstract controls,in which the HTML rendered can be quite different from the model that you program against .For example, a RADIOBUTTONLIST web server control might be rendered in a table or as inline text with other HTML.