Solved

run command line

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

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

623 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