- A recent task required me to populate and existing table inside an Microsoft SQL database from a flat .txt file. The T-SQL Bulk Insert command performed the task nicely.
Step 1: Create Format File with the bcp command. (If your your input and output file layouts are alike, this step may not be necessary.)
Log on to the machine where the database resides. Open up a command window and navigate to the binn directory (Program Files\Microsof Sql Server\...). The binn directory is where the bcp command resides.
From the command line enter:
bcp DatabaseName.Owner.TableName format nul -S ServerName -T -n -f Products.fmt
For more information on creating a format file see http://msdn.microsoft.com/en-us/library/ms191516.aspx
Step 2: Run Bulk Insert Command
--Without Format File
Bulk Insert dbo.fp_Products_work
From 'D:\temp\Products.txt'
With(FirstRow=2)
--With Format File
Bulk Insert dbo.fp_Products_work
From 'D:\Chuck\Products.txt'
With(FirstRow=2, FormatFile='D:\temp\Products.fmt')
Gotchas: 1) Your SQL Server account must be a member of the sysadmin or bulkadmin roles in order for you to use the Bulk Insert command. 2) In SQL 2000, the From clause does not allow you to use a variable (@Path) to provide path informatioin. My workaround in my stored procedure was to dynamically create an SQL string, and then execute the sql like so: Exec (@sql.
- Working with the DataGrid Control: Dynamic Bound Columns OnSortCommand event not being called.
Problem: The event/routine specified in the OnSortCommand attribute in the aspx:datagrid control was not being fired. I was also binding the datagrid columns dynamically in the code behind page.
Fix: When binding columns in the DataGrid dynamically, do so in the Page_Init event. By doing so, the event fired, and I was then able to sort the data.
Helpful Links: http://www.velocityreviews.com/forums/t97260-dynamic-bound-columns-onsortcommand-not-called-solution.html
I posted code on the link below showing how to sort columns in an ascending and descending manner.
http://www.codeproject.com/KB/webforms/SortingDataGridColumns.aspx
- Adding filter action to the ASP.NET FileUpload Control
Problem: The FileUpload control does not have a property to specify filter action on the FileUpload control. The following link provides techniques for filtering on both the client and server side: Adding Filter Action to FileUpload control of ASP.NET.
56d01603-e651-42f4-b611-7f140abd65bf|0|.0