Click here to Skip to main content
15,892,161 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
The below line in asp.net executes the input file xx.sql and provides the output in Output.txt file. But I need to get the output in the application itself, inside a gridview. My code needs to be in the same format mentioned in the below example itself. Please send me the modification that I need to do here so that the output will be displayed inside a grid instead of a txt file.

sqlCommand = "-U xx -P xx -S xxx -i D:\\xx.sql -o D:\Output.txt";
Process RunSQLScript = new Process();
RunSQLScript.StartInfo.FileName = "sqlcmd";
RunSQLScript.StartInfo.Arguments = sqlCommand;
RunSQLScript.Start();


What I have tried:

Tried with the below. But it prints the result in command prompt.
-U xx -P xx -S xxx\\sqlexpress -i D:\\xx.sql -p
Posted
Updated 12-Apr-17 17:50pm
v4
Comments
Richard Deeming 28-Mar-17 12:01pm    
So use ADO.NET[^] to load the data directly, rather than launching a separate process to run the query.

What's the question?
Member 13076177 4-Apr-17 5:50am    
Thank you for your suggestion. But using 'sqlcmd' utility is as part of the project requirement. So is there any way to get the output in a gridview by using sqlcmd itself
Richard Deeming 4-Apr-17 7:00am    
That's an absolutely absurd requirement!

Is this some sort of homework or interview question?

1 solution

The gridview and the sql command are not meant to work together. Sqlcommand is meant to maintain a database, not to load an application with it.

The best you could hope for is to convert the database to an xml file. Then you could load the xml file with an xml data source.

You will find many angry responses because the ado.net is meant to load things for this. Ado.Net is made to run directly with gridview. Who ever is requiring this is not good and is requiring you to use a bicycle when you have a car. Again, Sql command is an old tool for database work, not for loading Asp.Net.

Introduction to ASP.NET Web Forms: Grid View Control & Data Binding - YouTube[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900