SQL异常说明 [英] SQL Exception Explanation

查看:76
本文介绍了SQL异常说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在抛出对我没有任何意义的异常-想要一些帮助,有人来解释为什么会抛出该异常,以及我需要采取什么措施来解决此问题...

在我的C#代码中...

I am getting an exception thrown that doesn''t make any sense to me - and would like some help, someone to explain why this is being thrown, and what I need to do to solve the problem ...

In my C# code ...

 SqlConnection thisConnection = new SqlConnection(@"Network Library=DBMS;Data Source=AZ75;database=MyDev;User id=usrread;Password=password;";);
try
{
    thisConnection.Open();
}
catch (Exception e)
{
    Console.WriteLine(e.ToString());
}

 string sDocIDsList = "202+211, 30+30";

 SqlDataAdapter da = new SqlDataAdapter();
 DataSet ds = new DataSet();

 SqlCommand tCommand = new SqlCommand();
 tCommand.CommandText = "GetReport";
 tCommand.Connection = thisConnection;
 tCommand.CommandType = CommandType.StoredProcedure;

 da.SelectCommand = tCommand;

 tCommand.Parameters.Add(new SqlParameter("@Return_Value", SqlDbType.Int));
 tCommand.Parameters["@Return_Value"].Direction = ParameterDirection.ReturnValue;

 tCommand.Parameters.Add(new SqlParameter("@DocIDsList", SqlDbType.VarChar));
 tCommand.Parameters["@DocIDsList"].Value = sDocIDsList;
 tCommand.Parameters["@DocIDsList"].Direction = ParameterDirection.Input;

 ds.Clear();

 try
 {
     da.Fill(ds);
 }
 catch (SqlException e)
 {
     Console.WriteLine(e.Message);
 }



执行da.Fill命令时-系统引发异常,并显示以下文本:


子查询返回的值大于1.当子查询遵循=,!=,<,< =,>,> =时,或者当子查询用作表达式时,不允许这样做."


帮助 !!!



When executing the da.Fill command - the system throws an exception, with the following text:


"Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <=, >, >= or when the subquery is used as an expression"


HELP !!! What does this mean???

推荐答案



我猜您是在存储过程的选择查询中将值赋给变量.
或与子查询进行比较.该查询返回的行多.因此无法进行比较,因为存在多个值.
但是,除非发布存储过程的代码,否则无法弄清.


希望对您有所帮助.
Hi,

I guess you are either assigning value into a variable in your select query in the stored procedure.
or comparing with a sub query.That query is returning more than one row.so cannot be compared as there are multiple values.
However it cannot be clarified until you post the code of your stored procedure.


Hope this helps.


这意味着在您的存储过程中,您有一个子查询,该子查询返回多个值.您需要查看数据.

例如,如果您说

It means in your stored procedure you have a subquery that is returning more than one value. You need to look at your data.

For example, if you said

SELECT * FROM Table WHERE Column = (SELECT Column FROM Table2)



子查询将返回多个记录,但您使用的是=,因此会收到该错误.



The subquery will return more than one record but you are using = so you get that error.


这篇关于SQL异常说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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