Click here to Skip to main content
15,887,027 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: String.Format??? Pin
Jörgen Andersson9-Jul-10 10:23
professionalJörgen Andersson9-Jul-10 10:23 
GeneralRe: String.Format??? Pin
PIEBALDconsult9-Jul-10 10:33
mvePIEBALDconsult9-Jul-10 10:33 
GeneralRe: String.Format??? Pin
oggenok649-Jul-10 8:14
oggenok649-Jul-10 8:14 
GeneralRe: String.Format??? Pin
PIEBALDconsult9-Jul-10 8:59
mvePIEBALDconsult9-Jul-10 8:59 
GeneralRe: String.Format??? Pin
Jörgen Andersson9-Jul-10 10:48
professionalJörgen Andersson9-Jul-10 10:48 
GeneralRe: String.Format??? [modified] Pin
PIEBALDconsult9-Jul-10 10:51
mvePIEBALDconsult9-Jul-10 10:51 
GeneralRe: String.Format??? Pin
Jörgen Andersson9-Jul-10 11:06
professionalJörgen Andersson9-Jul-10 11:06 
GeneralRe: String.Format??? Pin
PIEBALDconsult9-Jul-10 12:29
mvePIEBALDconsult9-Jul-10 12:29 
Eureka!

In SQL Server 2008 (Express):
I created an Account table with ID (int) and Name (nvarchar) fields.
I populated the Account table with some records.
I created an IDdef User Defined Table Type with an ID (int) field.

In C# I instantiated a DataTable, added an ID (int) column.
Added some rows to the DataTable.

Then set up the following (db is an instance of one of my DALs, dt is the DataTable):

db.Command.CommandText = "SELECT * FROM Account WHERE ID IN ( SELECT ID FROM @IDs )" ;
                
System.Data.SqlClient.SqlParameter p = 
    new System.Data.SqlClient.SqlParameter 
    ( "@IDs" , System.Data.SqlDbType.Structured ) ;

p.TypeName = "dbo.IDdef" ;

p.Value = dt ;

db.Command.Parameters.Add ( p ) ;
               
db.Open() ;
                
System.Data.IDataReader dr = db.Command.ExecuteReader 
    ( System.Data.CommandBehavior.CloseConnection ) ;


And it works! Big Grin | :-D

I then changed the statement to SELECT * FROM Account INNER JOIN @IDs IDs ON Account.ID=IDs.ID

and that works too! Jig | [Dance] Jig | [Dance] Jig | [Dance] Jig | [Dance]
GeneralRe: String.Format??? Pin
Jörgen Andersson9-Jul-10 13:00
professionalJörgen Andersson9-Jul-10 13:00 
GeneralRe: String.Format??? Pin
PIEBALDconsult9-Jul-10 13:05
mvePIEBALDconsult9-Jul-10 13:05 
GeneralRe: String.Format??? Pin
PIEBALDconsult9-Jul-10 15:05
mvePIEBALDconsult9-Jul-10 15:05 
GeneralRe: String.Format??? Pin
Jörgen Andersson9-Jul-10 10:32
professionalJörgen Andersson9-Jul-10 10:32 
GeneralRe: String.Format??? Pin
PIEBALDconsult9-Jul-10 10:45
mvePIEBALDconsult9-Jul-10 10:45 
GeneralRe: String.Format??? Pin
Jeremy Hutchinson9-Jul-10 8:54
professionalJeremy Hutchinson9-Jul-10 8:54 
GeneralRe: String.Format??? Pin
Jörgen Andersson9-Jul-10 11:11
professionalJörgen Andersson9-Jul-10 11:11 
GeneralRe: String.Format??? Pin
CDP180211-Jul-10 20:43
CDP180211-Jul-10 20:43 
GeneralRe: String.Format??? Pin
Jason Christian22-Jul-10 9:05
Jason Christian22-Jul-10 9:05 
GeneralRe: String.Format??? Pin
PIEBALDconsult9-Jul-10 5:09
mvePIEBALDconsult9-Jul-10 5:09 
GeneralRe: String.Format??? Pin
oggenok649-Jul-10 5:35
oggenok649-Jul-10 5:35 
GeneralRe: String.Format??? Pin
PIEBALDconsult9-Jul-10 5:40
mvePIEBALDconsult9-Jul-10 5:40 
GeneralRe: String.Format??? Pin
Steve Wellens9-Jul-10 5:45
Steve Wellens9-Jul-10 5:45 
GeneralRe: String.Format??? Pin
PIEBALDconsult9-Jul-10 5:51
mvePIEBALDconsult9-Jul-10 5:51 
GeneralRe: String.Format??? Pin
Single Step Debugger9-Jul-10 6:16
Single Step Debugger9-Jul-10 6:16 
GeneralRe: String.Format??? Pin
M@dHatter11-Jul-10 10:33
M@dHatter11-Jul-10 10:33 
GeneralRe: String.Format??? Pin
Not Active11-Jul-10 10:53
mentorNot Active11-Jul-10 10:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.