« November 2005 | Main | January 2006 »

December 19, 2005

From DataReader to DataSet

Often you need to transform your DataReader into a DataSet. If that sounds weird or why should I just use SqlDataAdapter, the main problem is that I'm using strongly typed DataSet. SqlDataAdapter doesn't like the strongly typed data set. If your stored procedure is returning multiple tables, it will force it to be stored in Table1, Table2 ...

So a quick play with SqlDataReader gives me what I wanted. Here is the code snippet:
public void ExecuteQuery(DataTable[] dataTables)
{
    try
    {
        _cmd.Connection.Open();
        SqlDataReader sdr = _cmd.ExecuteReader();

        int tableNum = 0;
        while (sdr.Read())
        {
            DataRow dr = dataTables[tableNum].NewRow();
            for (int i = 0; i < sdr.FieldCount; i++)
            {
                string name = sdr.GetName(i);
                dr[name] = sdr.GetValue(i);
            }
            dataTables[tableNum].Rows.Add(dr);            
        }
        while (sdr.NextResult())
        {
            tableNum++;
            while (sdr.Read())
            {
                DataRow dr = dataTables[tableNum].NewRow();
                for (int i = 0; i < sdr.FieldCount; i++)
                {
                    string name = sdr.GetName(i);
                    dr[name] = sdr.GetValue(i);
                }
                dataTables[tableNum].Rows.Add(dr);    
            }
        }
    }
    finally
    {
        _cmd.Connection.Close();
    }
}


To the method you simply pass the order of the DataTable with the order of the SELECT statement in your stored procedure.

Posted by vhadiant at 06:16 PM | TrackBack

December 07, 2005

Commerce Server 2002 and XP

The original Commerce Server 2002 can't be installed in XP causing a major headache for me to do a proof of concept for my next project. After asking The Oracle turned out that you can install Commerce Server 2002 in XP. You just have to download Commerce Server 2002 SP3 and install the SP3. You still need to original Commerce Server 2002 installation disc.

Microsoft® Commerce Server Service Pack 3 (Commerce Server SP3) includes a setup program that enables you to install Commerce 2002 Developer Edition on Windows® XP or Windows 2000 Professional.

To install Commerce Server 2002 Developer Edition on Windows XP or Windows 2000 Professional :

1. On the Windows XP computer, download and extract Commerce Server SP3
2. Browse to the folder to which you extracted the service pack, and then double-click SetupDevEdition.exe.
3. When prompted, select the product installer (.msi file) for Commerce Server 2002 Developer Edition, and then proceed with the installation.
4. For Windows 2000 Professional, copy comdlg32.ocx from the \System32\Redist\MS\System folder to :\WinNT\System.
5. After installing Commerce Server 2002 Developer Edition, double-click SP3Setup.exe to apply Commerce Server SP3.
6. For instructions about running SP3Setup.exe, see Installing Commerce Server Service Pack 3 on One Computer.


Posted by vhadiant at 06:25 PM | TrackBack