CA.Service.dll中出现类型'System.Data.SqlClient.SqlException'的异常但未在用户代码中处理附加信息:'dbo'附近的语法不正确。 [英] An exception of type 'System.Data.SqlClient.SqlException' occurred in CA.Service.dll but was not handled in user code Additional information: Incorrect syntax near 'dbo'.
本文介绍了CA.Service.dll中出现类型'System.Data.SqlClient.SqlException'的异常但未在用户代码中处理附加信息:'dbo'附近的语法不正确。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public DataSet GetAllActiveTraining( int CompanyId)
{
try
{
SqlConnection conn = new SqlConnection(objConnection .GetConnection());
DataSet DsLoginData = new DataSet();
DsLoginData = SqlHelper.SqlHelper.ExecuteDataset(conn,CommandType.Text, 选择a.DocumentId,a。标题表格 [dbo]。[文件]作为内部联接[dbo]。[companydocument] AS b(a.DocumentId = b.DocumentId),其中a.hastest = 1,b.CompanyId = + CompanyId + 由a.Title ASC命令);
DsLoginData.Tables [ 0 ]。TableName = trainingmodule跨度>;
return DsLoginData;
}
catch (例外)
{
抛跨度>;
}
}
解决方案
这是因为一个小错字 - FORM 而是 FROM
试试这个 -
DsLoginData = SqlHelper.SqlHelper.ExecuteDataset(conn,CommandType.Text, 选择a.DocumentId,a.Title FROM [dbo]。[Document]作为内部联接[dbo]。[ companydocument] AS b on(a.DocumentId = b.DocumentId)其中a.hastest = 1且b.CompanyId = + CompanyId + 由a.Title ASC命令);
希望,它有帮助:)
一个错误是使用 FORM 而不是 FROM ,而b.CompanyId =+ CompanyId +由a.Title ASC命令
也可能因为你没有在companyId之后添加空格而抛出异常,它应该是b.CompanyId =+ CompanyId +由a.Title命令ASC
的要解决一些问题。正如已经指出的那样,你有一个拼写错误:FORM
应该是FROM
另一件事是您将值直接连接到SQL语句。不要这样做。它让您打开SQL注入,并可能很容易导致数据类型转换问题。而是使用 SqlParameter [ ^ 一>
public DataSet GetAllActiveTraining(int CompanyId)
{
try
{
SqlConnection conn = new SqlConnection(objConnection.GetConnection());
DataSet DsLoginData = new DataSet();
DsLoginData = SqlHelper.SqlHelper.ExecuteDataset(conn, CommandType.Text, "Select a.DocumentId,a.Title form [dbo].[Document] AS a inner join [dbo].[companydocument] AS b on (a.DocumentId=b.DocumentId) where a.hastest=1 and b.CompanyId=" + CompanyId + "order by a.Title ASC");
DsLoginData.Tables[0].TableName = "trainingmodule";
return DsLoginData;
}
catch (Exception)
{
throw;
}
}
解决方案
It's because of a small typo- FORM instead of FROM
Try this-
DsLoginData = SqlHelper.SqlHelper.ExecuteDataset(conn, CommandType.Text, "Select a.DocumentId,a.Title FROM [dbo].[Document] AS a inner join [dbo].[companydocument] AS b on (a.DocumentId=b.DocumentId) where a.hastest=1 and b.CompanyId=" + CompanyId + " order by a.Title ASC");
Hope, it helps :)
one mistake is using FORM instead of FROM, andb.CompanyId=" + CompanyId + "order by a.Title ASC
also may throw exceptions becouse you haven't add space after companyId, it should beb.CompanyId=" + CompanyId + " order by a.Title ASC
There are a few things to fix. As already pointed out you have a spelling mistake:FORM
should beFROM
Another thing is that you concatenate values directly to the SQL statement. Don't do this. It leaves you open for SQL injection and may easily cause problems in data type conversions. Instead use SqlParameter[^]
这篇关于CA.Service.dll中出现类型'System.Data.SqlClient.SqlException'的异常但未在用户代码中处理附加信息:'dbo'附近的语法不正确。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文