Solved

run command line

Posted on 2004-09-08
4
3,149 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
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

856 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