RE: Yet another command line parsing system

This looks like a logical way to handle command line parameters while still following convention of using an app.config file.

….I used another arguments parser from Code Project, “C#/.NET Command Line Arguments Parser“.
I like it because it works like the ASP.NET querystring parser – it handles the parsing (quoted strings, different delimiter styles) and exposes a string dictionary with the results.

I use a GetSettings accessor that reads the default from the app.config file, but allows overrides via command line. I like this approach because settings are their standard location (app.config), and any config setting can be overriden via command line without an attribute change and a recompile.

[STAThread]
private static int Main(string[] args)
{
    Processor processor1 = 
new Processor(args);
    
return processor1.Process();
}

private Arguments arguments;

public Processor(string[] args)
{
    
this.arguments = new Arguments(args);
}

public Process()
{
    Console.WriteLine(
this.GetSetting(“PreventEvil”));
}

private string GetSetting(string key)
{
    
string setting = string.Empty;
    
if (this.arguments[key] != null)
    {
        setting = 
this.arguments[key];
    }
    
else
    
{
        setting = ConfigurationSettings.AppSettings.Get(key);
    }
    
if (setting == null)
    {
        
return string.Empty;
    }
    
return setting;
}

[via [JonGalloway.ToString()]]

Fun with BCP

Here’s a quick and dirty way to export a table to a text file with SQL Server. With some minor tweaking, it should also work for views and stored procedures that return result sets.

Here is a simple method of exporting all the data from SQL Server table to a Text File

CREATE Procedure BCP_Text_File

@table varchar(100), 
@FileName varchar(100) 

as 
If exists(Select * from information_Schema.tables where table_name=@table)
    Begin
        Declare @str varchar(1000) 
        set @str=’Exec Master..xp_Cmdshell ”bcp “Select * from ‘+db_name()+’..’+@table+'” queryout “‘+@FileName+’” -c”’ 
        Exec(@str) 
    end
else
    Select ‘The table ‘+@table+’ does not exist in the database’

Execute this procedure by giving Table Name and the File Name

EXEC BCP_Text_File ‘Employee’,’C:\emp.txt’

Now all the data from Employee table will be exported to the text file which will be located at C:\emp.txt

[from WebLogs @ SqlJunkies.com]