Showing posts with label DataSource Controls. Show all posts
Showing posts with label DataSource Controls. Show all posts

Wednesday, August 14, 2013

Datasource Controls in Asp.net


The data source controls are available from asp.net 2.0(Not bound controls).Using this controls we can automate the task of creating data object.Normally we have to prepare data object programatically(using code).Whenever use these controls we may get some question regarding wizard approach features then one programmatic object will be created most importantly these controls provide complete customization options.The following data source controls are available in Asp.net

1.SQL Data source control
2.LINQ Data source control
3.Object Data source control
4.XML Data source control
5.Ado.net entity framework Data source control

1.Sql Data source control:
it is used to prepare data object from any SQL supported database Oracle,SqlServer,Access,My Sql,SYSbase,Informix,Ingres etc


Features:
The DS controls supports caching features . Data source controls does not Cache any data.with enable cache property of it we can add caching support.The reason to cache data is to avoid DB trips for every request.If data is cached then we retrieve data from they cache only by avoiding db.This will improve performance like anything.Different property for caching are also supported for maintaining time ,dependency etc
Conflict Detection(Concurrency control)
Using Data source controls when we manipulate data there is every possibility of occurring concurrency problems because web is for all and also our form can be accessed many users . DS controls provide conflict detection with 2 option

i)Override changes
ii)Compare all values

Thursday, July 18, 2013

Bind data to RadioButtonList with arraylist in asp.net

Title:
How to bind data to web server control using array list in asp.net using c#

Description:
Array list can hold list of items of similar data type.When  we want  declare the array list with specific size,no need to set the size of array list,because it can be re sizable automatically .

Example:
The below example will show how to add data statically and dynamically to radio button through array list.But  the binding concepts are also utilize for bind data to this standard control..Later articles i would like give all methods regarding array list

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;

public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ArrayList listNum = new ArrayList();
listNum.Add("b");
listNum.Add("h");
listNum.Add("a");
listNum.Add("k");
listNum.Add("r");
rbNumber.DataSource = listNum;
rbNumber.DataBind();
}
}
I hope it is helping for you.Thanks for coming and visit again

Monday, January 7, 2013

Get the dropdown selected value in asp.net using c#.net

Title:
How to get the drop down list selected value in asp.net using c#

Description:
The drop down list will display the list of items and each list of item is selectable.The best thing  of this control is ,we can bind static data or dynamic data which is to be done by using data binding concept.Now we know this control can support data binding

Example:
Some recent posts on drop down list selected value ,Jquery Drop down list validation .Now i would like to give an example on  how to get the drop down selected value in asp.net using c#.Before going to start ,we have to add one drop down list with label control which will be used to  display the drop down selected value .
Note:One more thing we need to remember i:e auto post back property set to true.If you want to see the properties of web control ,focus on control and click on F4

Aspx page:
<asp:DropDownList class="HTML" id="ddlcitytest" name="code" onselectedindexchanged="ddlcitytest_SelectedIndexChanged" runat="server"AutoPostBack="True">
<asp:ListItem>Please select</asp:ListItem>
<asp:ListItem>Hyderabad</asp:ListItem>
<asp:ListItem>Chennai</asp:ListItem>
<asp:ListItem>Bombay</asp:ListItem>
<asp:ListItem>Delhi</asp:ListItem>
</asp:DropDownList>
<asp:Label ID="lblcity" runat="server" Text="Label"></asp:Label>

codebehind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class About : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ddlcitytest_SelectedIndexChanged(object sender, EventArgs e)
{
//Get the selected value
lblcity.Text = ddlcitytest.SelectedValue.ToString();
}
}
In the above code the selected value has been assigned to label for display purpose.


Tuesday, April 17, 2012

How to use DataReadear in asp.net

Title: What is Data Reader and How to use Data reader

Description:Data reader is Read only and forward only.Simple description for those two properties
Read Only-->Data Reader doesn't support manipulation[insert,delete]
Forward Only-->Data Reader supports Reading records is forwarding direction[Reading only once]

VB.Net:
Dim cms As New OleDbCommand("select*from dept",cn)
Dim dr As OleDBDataReader
dr=cms.ExcuteReader()

C# Syntax:
Before going to use the data reader we should add the name System.Data.SqlClient to our application
SqlDataReader reader =new SqlDataReader();
dr.Read():-It will fetch a record into application process.It returns True fetching record is successfully else false
dr.Item(ColIndex/ColName) or dr(ColIndex/ColName) :-This can be used for any type of data
dr.GetData():-It will produce  better performance
dr.FieldCount:-It returns column count
dr.HasRows:-True:Records are available
                     False:Records are not available
dr.Close:-It will Release memory
dr is a pointer to the temp memory.where the records stored.
Data Reader will fetch record by record and it will consume only one record memory with in  application process.This will reduce burden on application process.Data Reader is strongly recommend when the application requirement is reading data only once with out manipulation

Thursday, March 22, 2012

How to update the XML file in asp.net

Title:How to read and update XML in asp.net using c#

Description: As per asp.net we have specific number of data source controls.Among these i have used XML data source control for my application.So now i would like to describe and explain about CRUD operations on XML file.As initial we have to get the data source path and read the data from the file .

Example:In the below example we have create a instance for XML document and load  from the specified path.Then i will get the all sales order id's using node list and iterate through the complete document.Mean while we are getting the sales Order customer title and update the name as per data
using System;
using System.Collections.Generic;
using System.Data;
using System.XML;

private void ReadAndUpdateXml_Click(object sender, EventArgs e)
{
XmlDocument newXmldoc= new XmlDocument();
newXmldoc.Load(Server.MapPath("~/XMLFiles/salesOrder.xml"));
XmlNodeList nodeList = newXmldoc.SelectNodes("//Orders/OrderId");
int i = 1;
foreach (XmlNode updatedNode in nodeList)
{
XmlNode updatedNode = newXmldoc.SelectSingleNode("//Orders/OrderId[position()='" +i + "']");
string salesOrderId = updatedNode.SelectSingleNode("ID").InnerText;
updatedNode.SelectSingleNode("Title").InnerText ="Specified Customer";
XmlNode UpdateTitle = newXmldoc.CreateNode(XmlNodeType.Element, "MetaTitle", null);
UpdateTitle.InnerText = "Desired Customer";
updateNode.AppendChild(UpdateTitle);
i++;
}
newXmldoc.Save(Server.MapPath("~/XMLFiles/salesOrder.xml"));
}

Bel