Site Meter Asp.Net-Csharp,Asp,Ado.Net,Ado,Micosoft,Visualstudio,Visual webgui: c#
Showing posts with label c#. Show all posts
Showing posts with label c#. Show all posts

Friday, December 11, 2009

Overview and example for Datatable in asp.net

Overview and example for Datatable in asp.net:


MEthod 1:


DataTable cTable = new DataTable();
DataRow d3;

cTable.Columns.Add("A", typeof(string));
cTable.Columns.Add("B", typeof(string));
cTable.Columns.Add("C", typeof(string));

d3 = cTable.NewRow();
d3[0] = "A:";
d3[1] = B;
d3[2] = "C";

cTable.Rows.Add(d3);


Method 2:

DataTable dtProducts = new DataTable();
DataColumn productColumn = new DataColumn();

productColumn.DataType = System.Type.GetType("System.Int32");
productColumn.ColumnName = "id";
productColumn.Unique = true;
dtProducts.Columns.Add(productColumn);


DataTable dtProducts = createProductDT();

DataRow aProduct = dtProducts.NewRow();

aProduct["id"] = 11;
aProduct["thumb"] = "images/widget0.jpg";
aProduct["name"] = "Red Widget";
aProduct["price"] = 19.99;
dtProducts.Rows.Add(aProduct);

Sunday, November 22, 2009

Download application or word or doc or pdf code in asp.net,c#

Download application or word or doc or pdf code in asp.net,c#
if (Page.IsPostBack){

Response.ContentType="application/ms-word";
Response.AddHeader( "content-disposition","attachment; filename=RegistrationFormDownload.pdf");
//Source from server
FileStream sourceFile = new FileStream(@"c:\inetpub\vhosts\www.com\httpdocs\Form.pdf", System.IO.FileMode.Open,System.IO.FileAccess.Read, System.IO.FileShare.Read );
//Source from Local system
FileStream sourceFile = new FileStream(@"system file path", System.IO.FileMode.Open,System.IO.FileAccess.Read, System.IO.FileShare.Read );
long FileSize;
FileSize = sourceFile.Length;
byte[] getContent = new byte[(int)FileSize];
sourceFile.Read(getContent, 0, (int)sourceFile.Length);
sourceFile.Close();

Response.BinaryWrite(getContent);
}

Saturday, November 14, 2009

To retrieve table data using table column in asp.net,C#

SqlDataReader rdr = null;
SqlConnection sqlcon = new SqlConnection("Server=___;Initial Catalog=____;Integrated security=true");
sqlcon.Open();

SqlCommand cmd1 = new SqlCommand("select * from ____;", sqlcon);
rdr = cmd1.ExecuteReader();
while (rdr.Read())
{
string ___ = rdr.GetString(rdr.GetOrdinal("column name"));
string ___ = rdr.GetString(rdr.GetOrdinal("column name"));

}
sqlcon.Close();

Substring in asp.net,c#

To find the last character in a string
string lastCharacter = myString.Substring(myString.Length - 1, 1);
//i.e. the last character is a SubString of myString, one character long, starting one character short of the length of myString

To remove the last two characters of a string
string myNewString = myString.Substring(0, myString.Length - 2);
//i.e. the new string is a SubString 2 characters shorter than myString, starting at the beginning of myString