Link to home
Start Free TrialLog in
Avatar of jgordin
jgordin

asked on

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

how to run sql statements using C# as a wrapper
Avatar of Hitesh Manglani
Hitesh Manglani
Flag of India image

Avatar of jgordin
jgordin

ASKER

i need a solution that would resemble running sql command in csh (unix).
uhhh could you explain a bit more what you want exactly? :?
Avatar of jgordin

ASKER

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.
Well.. most SQL servers have command line clients I guess..
what server are you targeting?  MS SQL Server?
Avatar of Bob Learned
Since I haven't used the C Shell with Unix, what kind of syntax/commands does it allow?  What do you need?

Bob
Avatar of jgordin

ASKER

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.
What database type are you using?

Bob
If you have SQL Server, there is the osql command line processor:

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

Bob
Avatar of jgordin

ASKER

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.
Avatar of jgordin

ASKER

any solution to this problem? thanks.
You could create a Console application that takes the arguments that you need, an runs the query and outputs the results.

Bob
Avatar of jgordin

ASKER

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
File | New Project | C# | Console application

Bob
Avatar of jgordin

ASKER

how do i execute and pass parameters to a file with sql statements? thanks.
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


Avatar of jgordin

ASKER

i need to execute a whole bunch of statements.

select * from test where test_col = "parameter"

update

select

etc..
ASKER CERTIFIED SOLUTION
Avatar of Hitesh Manglani
Hitesh Manglani
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial