Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Thursday, May 15, 2008

Convert ArrayList of Objects to DataTable

using System;using System.Collections;
using System.Data;using System.Reflection;
using System.Collections.Generic;
using System.Text;

public static class Util
{
public static DataTable ConvertArrayListToDataTable(ArrayList arrayList)
{
DataTable dt = new DataTable();

if (arrayList.Count != 0)
{
dt = ConvertObjectToDataTableSchema(arrayList[0]);
FillData(arrayList, dt);
}

return dt;
}

public static DataTable ConvertObjectToDataTableSchema(Object o)
{
DataTable dt = new DataTable();
PropertyInfo[] properties = o.GetType().GetProperties();

foreach (PropertyInfo property in properties)
{
DataColumn dc = new DataColumn(property.Name);
dc.DataType = property.PropertyType; dt.Columns.Add(dc);
}
return dt;
}

private static void FillData(ArrayList arrayList, DataTable dt)
{
foreach (Object o in arrayList)
{
DataRow dr = dt.NewRow();
PropertyInfo[] properties = o.GetType().GetProperties();

foreach (PropertyInfo property in properties)
{
dr[property.Name] = property.GetValue(o, null);
}
dt.Rows.Add(dr);
}
}
}

Friday, October 26, 2007

(70-528) Web-Based Client Development

Wiki
Preparation Guide
E-Snips
Flash Cards
Files 4 Sharing

.NET Videos

Educational Videos for .NET

Dot Net Rocks!
Learn Visual Studio
Channel 9
Learn ASP.NET
Windows Client.NET

Wednesday, October 17, 2007

Working with Oracle and ASP.NET 2.0

The Oracle Client with Enterprise Manager for remote administration
http://www.oracle.com/technology/software/products/database/oracle10g/htdocs/10201winsoft.html has the Oracle 10g Client. Choose ‘Administrator’ during installation to include the client and Enterprise Manager.

Oracle Express Database for local development / testing
Local installation should be the Oracle Express version for free at: http://www.oracle.com/technology/software/products/database/xe/index.html

Oracle SQL Developer for database design
http://www.oracle.com/technology/products/database/sql_developer/index.html

Friday, October 12, 2007

Oracle SQL and C# Dates

If you are working with Oracle and C#, you may need to insert a Date into the database. The way this is done, is to specifiy a date format and then let Oracle know what the format is by using the "to_date" function. One of the problems is that C# and Oracle specifiy date formats differently.

Here is one example:
strFromDate = myFromDate.ToString("MM/dd/yyyy hh:mm:ss tt");
strToDate = myToDate.ToString("MM/dd/yyyy hh:mm:ss tt");

_sqlQuery += "AND DATE_COMPLETED >= to_date('" + strFromDate + "', 'MM/DD/YYYY HH:MI:SS PM') ";
_sqlQuery += "AND DATE_COMPLETED <= to_date('" + strToDate + "', 'MM/DD/YYYY HH:MI:SS PM') ";

Wednesday, October 10, 2007

C# Back Button - Server Side (Not Javascript)


protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ViewState["originalUrl"] = Request.UrlReferrer.AbsoluteUri;
}
}

protected void btnBack_Click(object sender, EventArgs e)
{
Response.Redirect(ViewState["originalUrl"].ToString(), false);
}

Check This Out!

More Links to Good Information