Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

run command line

Posted on 2004-09-08
4
Medium Priority
?
3,154 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 1000 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 1000 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
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: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

719 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