Solved

run command line

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now