Showing posts with label dotnet. Show all posts
Showing posts with label dotnet. Show all posts

Update From Dataset ADO.Net

Sunday, July 4, 2010


he System.Data namespace consists mostly of the classes that constitute the ADO.NET architecture. The ADO.NET architecture enables you to build components that efficiently manage data from multiple data sources. In a disconnected scenario (such as the Internet), ADO.NET provides the tools to request, update, and reconcile data in multiple tier systems.

//Initialize Connection from database

SqlConnection cn = new SqlConnection("connectionString");

//add this Query command with connectionstring parameters to data adopter to get schema form database

SqlDataAdapter da = new SqlDataAdapter("Select * from tablename",cn);

// Dataset Object

DataSet ds = new DataSet();

//fill database schema to dataset

da.FillSchema(ds, SchemaType.Mapped);


DataRow dRow1 = ds.Tables["workers"].NewRow();

dRow1[1] = "Value1"; //textBox1.Text;

dRow1[2] ="Value2"; //textBox2.Text;

dRow1[3] ="Value3";///textBox3.Text;

dRow1[4] = "Value4";///textBox4.Text;

dRow1[5] = "Value5";//textBox5.Text;

ds.Tables["workers"].Rows.Add(dRow1);

SqlCommandBuilder builder = new SqlCommandBuilder(da);

da.Update(ds);

ds.AcceptChanges();

Nested Gridview Asp.net

Monday, December 21, 2009

Download Source Code

DropDownList In GridView (CRUD) Operation and Hide Row in Girdview

Wednesday, November 4, 2009


Update , Copy ,Record, Delete (CRUD) Operation Gridview in asp.net Programmability is little bit difficult but its just a few techniques game and nothing else that
like how to access edit values,add control in gridview and with data hide columns in girdview on runtime but
but column value should acesable and manymore. now in this totrial i will tell how to preform
Update , Copy ,Record, Delete (CRUD) Operation Gridview just few steps and you will do it by your selft

1 drag gridview on your form and autgeneratecolumn properties set to false

2 add 4Column type column 1,2 : boundedfield set there header and bindvalue col1 = Productid and cal2 = Productname and add 3rd column TemplateField type , 4th column command type checked update checkbox .

3 edit columns 1,2 and command columns convert on TemplateField

4 . click on gridview flag and edit template there you will see 4 columns in column 0 you have add dropdownlist .
5 select templatefooter in edittemplate add textbox in productname , dropdownlist in colum0 and label control in column productID endedittempalte
6 add database in aap_data folder form sample code
7 right click on girdview goto properties and fire three event 1 rowCreated, Rowupdateing,rowediting and past code give in sample code ;

8 add some css tag in header to hide productid



thank
Usama Wahab Khan
any help Contant me
usamawahabkhan@gmail.com

Microsoft DreamSpark for Students in Pakistan

Tuesday, October 6, 2009



Now Microsft introducing the best Gifts for student Call DreamSprak .DreamSpart is the Platform which will provide best opportunities specially for Pakistan we were lives in 3rd world country resources are alway matter for our student. On this issue Microsoft come`s like Farry God mother and this Program call the DREAMSPARK Deram comes true now Pakistan Student can development on world lastest Microsft technonogies with any fee and cost even a single peni and Learning Classes,Certification


its become`s free now just registartor , virifidd , download tree setp for sucessus by Microsoft so what are You waiting for go on Microsoft DreamSprak.com and get started millions of millions student were taking advantage of thisunbeliveable Offer by Microsoft for applying Microsft DreamSpark you just have Live Account and Select your country , find your Universit or Collage, school submit your identification information and download software online and get license key

List of Software


and enjoy and show the world what your dreams if you guys have any problem to find your Universities,Collages ,School so contact : contact Microsoft Student Partner at your University AND Contact Mic or Microsft led pakistanthank you

Print GridView , Report Builder

Thursday, October 1, 2009

Download Source Code

What’s new in ASP.NET 4.0

Sunday, August 16, 2009



With Visual Studio 2010 Beta 1 and .NET Framework Beta 1 out for some time, this post is due from me for a long time. ASP.NET 4.0 has many improvements for different set of scenarios such as Webforms, Dynamic Data & AJAX based web development. There are also a lot of enhancements to the core runtime that powers ASP.NET such as Caching, Session & Request/Response objects.

For this post, we will examine some of the web form enhancements. There are sure a lot of them and we will examine some of them in the future posts.

Controlling View State using the ViewStateMode Property – Performance Enhancement

One of the most complained thing in ASP.NET Webform is the growing viewstate which becomes a concern for performance. While earlier you can set the EnableViewState property to true or false, post that, all the controls, by default inherit and even if you set it to enabled at control level, the behaviour was inconsistent.

With ASP.NET 4.0, the ViewStateMode property helps to determine for every control, whether the ViewState should be enabled, disabled or inherited accordingly. Ex.-


When you run the above page, you can find that the intial value for both the labels is set to “Value set in code behind” whereas after clicking on the button (postback), the value of label1 changes to “Value set in markup” whereas the value of label2 remains unchanged. As you can see, the Panel which holds both these lables has ViewStateMode set to Disabled and label1 is inherting the mode (this is the default if not specified) and label2 has it enabled. That is the reason label2 maintains viewstate while label1 loses it.

While it is arguably possible using the simple EnableViewState property earlier, it was never consistent. Considering the fact that in most of our performance sessions, we talk about disabling viewstate and then enabling it at control level while it doesnt work, this ViewStateMode is a welcome architectural change to improve performance.

Page Meta Keyword & Description – Search Engine Optimization feature

Upto Visual Studio 2008, one can set the Title of the page declaratively or through program using Page.Title. However, as more and more web traffic is happening through search engines, Page’s Title, Keyword and description become more important. Although the Keyword feature was exploited and hence many search engines today ignore it, Page Description is something still major search engines such as Google, Bing use for identifying and indexing pages based on content.

The new feature in ASP.NET 4.0 allows users to programmatically set the Page Description and Keywords as follows:-


The above code appends the following markup


And the way it works is that, if the meta tags are already present in the HTML markup, whatever is set in the code behind will fill up the “content” part alone if the “name” tag is matching.

Although this looks simple, it is very useful in cases where you want to set these dynamically based on a condition / criteria. So far, these were set statically in the HTML. Now with Page Class level access, these can be set dynamically.

There are many more enhancements to Webforms such as Routing improvements, setting ClientID etc., which we will examine in the future posts.

Cheers !!!

use QueryString in Asp.net

Sunday, August 2, 2009



User query string in asp,.net
Download Source code

ADO . Net


ADO.NET provides consistent access to data sources such as Microsoft SQL Server, as well as data sources exposed through OLE DB and XML. Data-sharing consumer applications can use ADO.NET to connect to these data sources and retrieve, manipulate, and update data.
ADO.NET cleanly factors data access from data manipulation into discrete components that can be used separately or in tandem. ADO.NET includes .NET Framework data providers for connecting to a database, executing commands, and retrieving results. Those results are either processed directly, or placed in an ADO.NET DataSet object in order to be exposed to the user in an ad-hoc manner, combined with data from multiple sources, or remoted between tiers. The ADO.NET DataSet object can also be used independently of a .NET Framework data provider to manage data local to the application or sourced from XML.
The ADO.NET classes are found in System.Data.dll, and are integrated with the XML classes found in System.Xml.dll. When compiling code that uses the System.Data namespace, reference both System.Data.dll and System.Xml.dll.


// Add Namespace of sqlClient

using System.Data.SqlClient;

private static string strConnection ="user id=sa;password=openthegate;database=northwind;server=DevServer";


public OrderGrid()
{
Page.Init += new System.EventHandler(Page_Init);
}

// Connect to the Database

private SqlConnection GetConnection()
{
SqlConnection objConnection = new SqlConnection(strConnection);
return objConnection;
}
// this method will populate the DataGrid OrdGrid

private void PopulateGrid()
{
// Connect to the Database
SqlConnection objConnection=GetConnection();
objConnection.Open();
DataSet objDataSet = new DataSet("OD-Prod");
SqlDataAdapter objDataAdapter = new SqlDataAdapter();
// copy the table Order Details in to the DataSet
string strCmd="SELECT OD.ProductID,OD.Quantity,P.ProductName FROM [Order Details] OD, ";
strCmd+=" Products P WHERE OD.ProductID=P.ProductID AND ";
if(OrderID.Text.Length>0)
{
strCmd+="OD.OrderID = "+ OrderID.Text;
}
else
{
objConnection.Close();
return;
}
SqlCommand selCommand = new SqlCommand(strCmd,objConnection);
objDataAdapter.SelectCommand=selCommand ;
objDataAdapter.Fill(objDataSet,"JoinTable");
OrdGrid.DataSource =objDataSet.Tables["JoinTable"];
OrdGrid.DataBind();

}
private void InitializeComponent()
{
this.OrdGrid.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.CancelGrid);
this.OrdGrid.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.EditGrid);
this.OrdGrid.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.UpdateGrid);

}

protected void SerchClicK(object sender, System.EventArgs e)
{
this.PopulateGrid();
}


System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
OrdGrid.EditItemIndex= e.Item.ItemIndex;
PopulateGrid();
// prevent the TextBox from changeing the OrderID
OrderID.Enabled=false;

}

// Eventhandler for the event Cancel the Edit(DataGrid)
private void CancelGrid(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
OrdGrid.EditItemIndex=-1;
PopulateGrid();
// able the TextBox to change the OrderID
OrderID.Enabled=true;

}


private int DirectCommand(string strCmdText)
{
SqlConnection objConnection = GetConnection();
SqlCommand objCommand = new SqlCommand(strCmdText,objConnection);
objCommand.Connection.Open();
int nAffected = objCommand.ExecuteNonQuery();
objConnection.Close();

return nAffected;

}

// Eventhandler for the event Updating the DataGrid
private void UpdateGrid(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string strQuantity= ((TextBox)e.Item.Cells[3].Controls[0]).Text;
string strProductID = e.Item.Cells[1].Text;
string strUpdate ="UPDATE [Order Details] SET Quantity = "+strQuantity;
strUpdate+=" WHERE OrderID = "+ OrderID.Text;
strUpdate += " AND ProductID = "+strProductID;
// Update the table "Order Details"
int nCheck = DirectCommand(strUpdate);

OrdGrid.EditItemIndex=-1;
PopulateGrid();
// able the TextBox to change the OrderID
OrderID.Enabled=true;
}
}
}
One more option to delete the row
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Data" %>
<%@ Language=C# Debug="True" %>
<html>
<head>
<script runat="server">
public void Page_Load()
{
OleDbConnection conStudent;
OleDbCommand cmdAuthDel;
string myConnString;
string strDelete;

myConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=c:\\inetpub\\wwwroot\\dataaccess\\Northwind.mdb;";
conStudent = new OleDbConnection( myConnString );

strDelete = "DELETE * FROM Student WHERE au_fname=’Usama’";
cmdAuthDel = new OleDbCommand( strDelete, conStudent );

conStudent.Open();
cmdAuthDel.ExecuteNonQuery();
conStudent.Close();
}

<meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">

<body>
Records deleted!


By
Usama Wahab Khan and Atif Shahzad