Solved

run command line

Posted on 2004-09-08
4
3,151 Views
Last Modified: 2008-01-09
I usually write webased applications but this time i need a windows app (C#) to execute a couple command line commands and execute a stored procedure in a remote database (SQL SERVER), is this possible? please give a sample thanks
0
Comment
Question by:vinny45
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 12010944
from MSDN:

// Factorial_main.cs
// arguments: 3
using System;
public class Factorial
{
   public static long Fac(long i)
   {
      return ((i <= 1) ? 1 : (i * Fac(i-1)));
   }
}

class MainClass
{
   public static int Main(string[] args)
   {
      // Test if input arguments were supplied:
      if (args.Length == 0)  
      {
         Console.WriteLine("Please enter a numeric argument.");
         Console.WriteLine("Usage: Factorial <num>");
         return 1;
      }

      // Convert the input arguments to numbers:
      try
      {
           long num = long.Parse(args[0]);
           Console.WriteLine("The Factorial of {0} is {1}.",
                        num, Factorial.Fac(num));
           return 0;
      }
      catch (System.FormatException)
      {
         Console.WriteLine("Please enter a numeric argument.");
         Console.WriteLine("Usage: Factorial <num>");
         return 1;
      }
   }
}
0
 
LVL 15

Assisted Solution

by:Timbo87
Timbo87 earned 250 total points
ID: 12010960
The code is identical to a web based implementation.

using System.Data;
using System.Data.SqlClient;

SqlConnection conn = new SqlConnection("connection string");
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "sp_DoStuff";
cmd.CommandType = CommandType.StoredProcedure;
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();


This is just some example code. If you need more help, please provide some specifics on your problem.
0
 
LVL 4

Accepted Solution

by:
thedude112286 earned 250 total points
ID: 12011011
For the command line bit:

System.Diagnostics.Process.Start("c:\ProgramToRun.exe -CommandLineOptions");

Looks like Timbo has the Sql Stored Procedure covered.
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 12011025
whoops I rea dit wrong I thought he meant take a few command line args for the sproc.
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question