为什么某些存储过程不返回ASP.Net C#中的数据 [英] Why some stored procedures do not return data in ASP.Net C#

查看:74
本文介绍了为什么某些存储过程不返回ASP.Net C#中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做的是使用C#在ASP.Net上生成一个文本文件.通过执行存储过程从数据库中检索数据.我确保存储过程通过在SQL Server Mangement Studio中执行它来返回值.我实际上能够做到这一点.

What I tried to do is generating a text file on ASP.Net using C#. The data is retrieved from a database by executing a stored procedure. I ensured that the stored procedures returned values by executing it in SQL server Mangement Studio. I was actually able to do just that.

我首先将所有相关表收集到一个视图中,然后使用存储过程从该视图中获取数据.然后将这些数据生成到ASP.Net中的文本文件中.使用以下代码:

I first gether all related tables into a view then using stored procedure to get data from that view. Then generate that data into text file in ASP.Net. using the following code:

SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Name"].ConnectionString);
conn.Open();
SqlCommand cmd = new SqlCommand("Stored Procedure Name", conn);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter myAdapter = new SqlDataAdapter(cmd);        
DataTable dt = new DataTable();
myAdapter.Fill(dt);           
System.Text.StringBuilder strResult = new System.Text.StringBuilder("");
string createtext = (Server.MapPath("./Feeds/") + "feed.txt");
StreamWriter w = File.CreateText(createtext);
w.Flush();
w.Close();

我确保每个视图也返回值(在SQL Server Management Studio中).

I ensured that every view returned values as well (in SQL Server Management Studio).

但是问题是,尽管所有存储过程在SQL Server Management Studio中都返回了一些值,但并非所有存储过程都在ASP.Net上返回了值,我只能得到空白文本文件.

But the problem is that not all stored procedures returned values on the ASP.Net I only get blank text file eventhough all stored procedures returned some values in SQL Server Management Studio.

我只在

select Somthing 
from View_Name 

此查询在Management Studio中返回某些值,但在ASP.Net中返回某些值(对于某些存储过程).

This query returns some value in the Management Studio, but not ASP.Net (for some stored procedures).

此问题可能是什么问题?请帮助

What could be the issue for this problem? Please help

推荐答案

我看不到将数据表中的数据放入文本文件的位置.

I don't see where you have taken the data in your DataTable and put it into the text file.

由于您已在注释中显示了代码:

Since you have shown your code in the comments:

看来您正在吞下例外.如果您只是为了简洁起见而忽略了代码,但如果不这样做,那么您可能会在catch语句中隐藏错误,因为除了异常外,您什么也没做.

It appears you are swallowing your exceptions. If you were just leaving the code out for brevity great but if not then you could be hiding an error on the catch statement since you aren't doing anything with the exception.

例如,您可能在SP或View上遇到权限问题,却不知道.

For example you could be having a permissions issue on an SP or View and don't know it.

如果不是这种情况,则:调试/为此代码添加一个断点,以查看数据表中是否有数据.

If that isn't the case then: Debug / add a breakpoint for this code to see if the datatable has data.

您还可以使用SQL事件探查器查看从代码到SQL Server的内容.

You could also use SQL Profiler to see what is getting to SQL Server from your code.

这篇关于为什么某些存储过程不返回ASP.Net C#中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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