Click here to Skip to main content
15,885,278 members
Home / Discussions / C#
   

C#

 
GeneralRe: how to set half Pixel size in C# Pin
Richard MacCutchan19-Dec-13 1:18
mveRichard MacCutchan19-Dec-13 1:18 
GeneralRe: how to set half Pixel size in C# Pin
GuyThiebaut19-Dec-13 20:06
professionalGuyThiebaut19-Dec-13 20:06 
QuestionDeserialize dictionary with datacontractserializer c# Pin
Member 1047521718-Dec-13 8:35
professionalMember 1047521718-Dec-13 8:35 
AnswerRe: Deserialize dictionary with datacontractserializer c# Pin
BillWoodruff18-Dec-13 9:38
professionalBillWoodruff18-Dec-13 9:38 
QuestionHow to avoid compression options pop up box in avisaveoptions Pin
delphix518-Dec-13 8:13
delphix518-Dec-13 8:13 
QuestionHow Choice Avimanger compression from code Pin
delphix518-Dec-13 7:54
delphix518-Dec-13 7:54 
NewsRun SQL Scripts From C# Pin
Kevin Marois18-Dec-13 6:23
professionalKevin Marois18-Dec-13 6:23 
GeneralRe: Run SQL Scripts From C# Pin
Richard Deeming18-Dec-13 7:06
mveRichard Deeming18-Dec-13 7:06 
Just a plain .sql script file? You just need to read the file into a string and execute that string as a command. The only potential issue is if the file contains a batch delimiter such as GO, in which case you need to execute each batch separately.

C#
private static IEnumerable<string> ReadCommandBatches(IEnumerable<string> lines)
{
   var builder = new StringBuilder();
   forach (string line in lines)
   {
      if (string.Equals(line, "GO", StringComparison.OrdinalIgnoreCase))
      {
         if (builder.Length != 0)
         {
            yield return builder.ToString();
            builder = new StringBuilder();
         }
      }
      else
      {
         builder.AppendLine(line);
      }
   }
   
   if (builder.Length != 0)
   {
      yield return builder.ToString();
   }
}

public static void ExecuteScriptFile(SqlTransaction transaction, string filePath)
{
   var lines = File.ReadLines(filePath);
   foreach (string batch in ReadCommandBatches(lines))
   {
      using (var command = new SqlCommand(batch, transaction.Connection, transaction))
      {
         command.ExecuteNonQuery();
      }
   }
}




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: Run SQL Scripts From C# Pin
Kevin Marois18-Dec-13 7:07
professionalKevin Marois18-Dec-13 7:07 
GeneralRe: Run SQL Scripts From C# Pin
V.18-Dec-13 21:01
professionalV.18-Dec-13 21:01 
QuestionRead comma delimited .txt file with large number of data - do search in column A Pin
lordoftrades18-Dec-13 2:15
lordoftrades18-Dec-13 2:15 
AnswerRe: Read comma delimited .txt file with large number of data - do search in column A Pin
Richard MacCutchan18-Dec-13 2:47
mveRichard MacCutchan18-Dec-13 2:47 
GeneralRe: Read comma delimited .txt file with large number of data - do search in column A Pin
lordoftrades18-Dec-13 2:48
lordoftrades18-Dec-13 2:48 
AnswerRe: Read comma delimited .txt file with large number of data - do search in column A Pin
Manfred Rudolf Bihy18-Dec-13 2:55
professionalManfred Rudolf Bihy18-Dec-13 2:55 
GeneralRe: Read comma delimited .txt file with large number of data - do search in column A Pin
lordoftrades18-Dec-13 3:03
lordoftrades18-Dec-13 3:03 
GeneralRe: Read comma delimited .txt file with large number of data - do search in column A Pin
Manfred Rudolf Bihy18-Dec-13 3:13
professionalManfred Rudolf Bihy18-Dec-13 3:13 
AnswerRe: Read comma delimited .txt file with large number of data - do search in column A Pin
BillWoodruff18-Dec-13 3:32
professionalBillWoodruff18-Dec-13 3:32 
GeneralRe: Read comma delimited .txt file with large number of data - do search in column A Pin
Manfred Rudolf Bihy18-Dec-13 3:53
professionalManfred Rudolf Bihy18-Dec-13 3:53 
GeneralRe: Read comma delimited .txt file with large number of data - do search in column A Pin
BillWoodruff18-Dec-13 4:30
professionalBillWoodruff18-Dec-13 4:30 
GeneralRe: Read comma delimited .txt file with large number of data - do search in column A Pin
lordoftrades18-Dec-13 4:12
lordoftrades18-Dec-13 4:12 
AnswerRe: Read comma delimited .txt file with large number of data - do search in column A Pin
jschell18-Dec-13 9:09
jschell18-Dec-13 9:09 
GeneralRe: Read comma delimited .txt file with large number of data - do search in column A Pin
lordoftrades18-Dec-13 9:59
lordoftrades18-Dec-13 9:59 
GeneralRe: Read comma delimited .txt file with large number of data - do search in column A Pin
jschell19-Dec-13 14:10
jschell19-Dec-13 14:10 
AnswerRe: Read comma delimited .txt file with large number of data - do search in column A Pin
BillWoodruff18-Dec-13 11:18
professionalBillWoodruff18-Dec-13 11:18 
GeneralRe: Read comma delimited .txt file with large number of data - do search in column A Pin
lordoftrades18-Dec-13 11:22
lordoftrades18-Dec-13 11:22 

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.