?
Solved

C# wrapper for sql statements (similar to csh on unix that runs sql commands)

Posted on 2007-07-25
18
Medium Priority
?
858 Views
Last Modified: 2012-06-22
how to run sql statements using C# as a wrapper
0
Comment
Question by:jgordin
  • 8
  • 6
  • 2
  • +1
18 Comments
 
LVL 13

Expert Comment

by:hiteshgoldeneye
ID: 19567747
0
 

Author Comment

by:jgordin
ID: 19567785
i need a solution that would resemble running sql command in csh (unix).
0
 
LVL 3

Expert Comment

by:Nico
ID: 19567826
uhhh could you explain a bit more what you want exactly? :?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jgordin
ID: 19567891
1. i have a bunch sql statement
2. i need to run those statement in batch
3. one can do it chs c -shell) script on unix.  I would like to do that in #C .net application. that is, a shell/wrapper that would execute my sql statements.
0
 
LVL 3

Expert Comment

by:Nico
ID: 19568016
Well.. most SQL servers have command line clients I guess..
what server are you targeting?  MS SQL Server?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 19568153
Since I haven't used the C Shell with Unix, what kind of syntax/commands does it allow?  What do you need?

Bob
0
 

Author Comment

by:jgordin
ID: 19568240
C shell in unix allows to create *.csh file when one can specify sql commands:

file.csh:

isql -S ....

select * from test ...

I need to be able to do similar things in c# .net.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 19568305
What database type are you using?

Bob
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 19568327
If you have SQL Server, there is the osql command line processor:

    osql -ddatabase -sserver -E -q"Select * From Table"

Bob
0
 

Author Comment

by:jgordin
ID: 19568362
microsoft sql server. i need to have a wrapper that allows to run sql statements that are in *.xml or *.txt file. i also need to pass parameters to sql commands.
0
 

Author Comment

by:jgordin
ID: 19568670
any solution to this problem? thanks.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 19568791
You could create a Console application that takes the arguments that you need, an runs the query and outputs the results.

Bob
0
 

Author Comment

by:jgordin
ID: 19568902
what is a console application?

here is what i need:

file1:

select * from test whe test_col = parameter(passed from file2)
update
update

file2:

execute file1 statements
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 19569030
File | New Project | C# | Console application

Bob
0
 

Author Comment

by:jgordin
ID: 19569128
how do i execute and pass parameters to a file with sql statements? thanks.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 19569231
The main method in the Program.cs file looks like this:

        static void Main(string[] args)
        {
        }

'args' is a string array of arguments that you can pass to the executable.

Example:
SqlQuery -sserver -ddatabase -iinputfile

Bob


0
 

Author Comment

by:jgordin
ID: 19569449
i need to execute a whole bunch of statements.

select * from test where test_col = "parameter"

update

select

etc..
0
 
LVL 13

Accepted Solution

by:
hiteshgoldeneye earned 2000 total points
ID: 19571903
to execute a bunch of statements you can store them line by line in a text file, start reading them into a string and execute it one by one.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
User Beware!  This is a rather permanent solution to removing your email from an exchange server.  The only way to truly go back is to have your exchange administrator restore your mailbox from backups.  This is usually the option of last resort.  A…
Viewers will learn the different options available in the Backstage view in Excel 2013.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…

850 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