如何在ASP.NET中使用sqlcmd和gridview [英] How to use sqlcmd and gridview in ASP.NET

查看:59
本文介绍了如何在ASP.NET中使用sqlcmd和gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

asp.net中的以下行执行输入文件xx.sql并在Output.txt文件中提供输出。但是我需要在gridview中获取应用程序本身的输出。我的代码需要采用下面示例本身提到的相同格式。请发送我需要在此处进行的修改,以便输出显示在网格内而不是txt文件中。



 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();





我尝试过:



尝试以下。但它会在命令提示符下打印结果。

-U xx -P xx -S xxx \\sqlexpress -i D:\\xx.sql -p

解决方案

< blockquote> gridview和sql命令不是一起工作的。 Sqlcommand旨在维护数据库,而不是使用它加载应用程序。



你最希望的是将数据库转换为xml文件。然后你可以用xml数据源加载xml文件。



你会发现很多愤怒的回答,因为ado.net是为了加载这个东西。 Ado.Net可以直接使用gridview运行。谁曾经要求这样做并不好,并且要求你在有车时使用自行车。同样,Sql命令是用于数据库工作的旧工具,而不是用于加载Asp.Net。



ASP.NET Web窗体简介:网格视图控件&数据绑定 - YouTube [ ^ ]

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

解决方案

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[^]


这篇关于如何在ASP.NET中使用sqlcmd和gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆