Monday, March 12, 2012

How to copy a complex query result into a csv in file system

hi

How to copy a complex query result into a csv in file system

Regards

Rajesh

exuberantleon@dotnet.itags.org.yahoo.co.in

You didn't give much details. A way would be:

-Create a text file with csv extension.

-ExecuteReader()

-Write column names on first line separated by commas

while ( reader.Read() )

{

// Write row data, fields separated by commas and " as string delimiter. Each row ends with a CRLF pair

}


It depends on source of the data. In a case of SQL Server, you could write SQL DTS job that does it for you. If you have data in a DataSet, then you could use method described in CetinBasoz post or transform DataSet's XML into CSV using XSL

Labels: , , , , , , , , ,

How to convert time format

Hi all,

I had query some time information from the database and use a dataset to bind to a GridView.

But unfortunately, the time that display on the GridView is not my desired choice.

It was display as "3/1/2007 10:06:27 PM".

Does anyone know how to convert it as "3/1/2007 22:06:27"?

Part of my code is as follow

pgDataAdapter.Fill(ds,

"Start Time");

Thanks

Hi bslim67,

You can use the DataFormatString property of the GridView column to format the datetime value.

Hope this helps.


Hi,

Hi,

I had tried this.

<asp:BoundFieldDataField="starttime"dataformatstring="{0:dd/MMM/yy}"

HeaderText

="Start Time"ReadOnly="True"SortExpression="starttime"/>

But when I run the program during runtime, it seems that it did not take effect.

It still show me the date and time though my dataformat is only on date.

Please help.

Thanks


Dear , friend:

You should set HtmlEncode=false in the markup of:BoundField

I hope the above information will be helpful. If you have any issues or concerns, please let me know. It's my pleasure to be of assistance


Hi,

Thanks for your info. It's really a great help for me.

Labels: , , , , , , , , , , ,

How to convert a date field to short date? without time.

I am using a query builder to buld a sql statement which brings me somes fields which are defined as date, and they are brought like this one: 5/17/2006 12:00:00 AM and I just want to bring the 5/17/2006.

I tried

CONVERT (CHAR(10), Fecha_evento, 101) ASFecha_evento

It works, for displaying, but when I try to look for the maximun within that field, it interprets it as a string, so I do not get the right value. Do you have a way to solve this? thanks a lot!

There's really no such thing as a date without a time. If you're having problems with displaying the information on a form, you should look at formatting the value, rather than changing the actual value that's retrieved. Setting your format string to "{0:MM/dd/yyyy}" should format it as you've indicated above.

Labels: , , , , , , , , , , , , , , ,