John Stagich's Blog

Microsoft .Net Developer

Virtual Team System Users Group/ScreenCastADay

clock September 17, 2008 13:27 by author johnstagich

Here are two more Team System/.Net/SQL/ resources.

Team System User Group - Virtual Edition

Screen Cast A Day


John


September 2008 Quick Hits

clock September 8, 2008 09:38 by author johnstagich
  1. 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.
 
  1. 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

  1. 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.


About the author

I am the owner of Stagich Software Consulting.  Stagich Software Consulting specializes in developing Microsoft .Net/Microsoft SQL software applications.

 

Calendar

<<  August 2014  >>
MoTuWeThFrSaSu
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567

View posts in large calendar

Month List

Category list

None

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

Sign In