Thursday, September 24, 2009

SQL Server select data from CSV as if it were a table

I can select without using DTS or a linked server.

SELECT * FROM OPENROWSET
('MICROSOFT.JET.OLEDB.4.0','Text;Database=C:\Folder\;',
'SELECT * FROM [Report.csv]') MyAlias

You may need these permissions
sp_configure 'Ad Hoc Distributed Queries', 1
reconfigure

You may have problems on X64

Thursday, October 09, 2008

Linq: Split string array and convert into integer using a converter / lambda and then selecting where in or contains from that list

// This will split an CSV string array into an array of integers
int[] intArr = Array.ConvertAll( priorityCsv.Split(','), n => Convert.ToInt32(n) );

//This will select the count of values where there are in or contain the values in the array
return (from v in this.Context.VACompanyErrors where intArr.Contains(v.Priority) select v).Count();

Tuesday, May 20, 2008

fill text box with nullable type or empty

fill text box with nullable type or empty
txtExpectedCloseDateTextBox.Text = olo.ExpectedCloseDate.ToString() ?? string.Empty;

Friday, April 25, 2008

iterate

list.ForEach(delegate(MyType x) { x.Property1.Replace("AAAA", "").Replace("BBBB", ""); });
OneType one = OneTypeList.Find(delegate(OneType ooo) { return oood.Value == "findstring; });