繁体   English   中英

错误 'LoginName' 附近的语法不正确。 在 C# 中

[英]error Incorrect syntax near 'LoginName'. in c#

我收到此错误 'LoginName' 附近的语法不正确。 在 C# 中

public Data Table Select Data(string stored_Procedure,sqlParameter[] para)
{
  SqlCommand sqlCom = new SqlCommand();
  sqlCom.CommandText = stored_Procedure;
  sqlCom.Connection = con;
  if(para!=null)
  {
      for(int i =0;i<para.Length;i++)
      {

         sqlCom.Parameters.Add(para[i]);
      }
  }
   SqlDataAdapter dt = new SqlDataAdapter(sqlCom);
   DataTable Dt = new DataTable();
   dt.Fill(Dt);
   return Dt;
}

您必须指定CommandType = CommandType.StoredProcedure (默认为Text ):

sqlCom.CommandText = stored_Procedure; // name of stored-Procedure;
sqlCom.CommandType = CommandType.StoredProcedure;

您的问题的原因是您的连接字符串没有针对正确的数据库。 然后找不到存储过程“找不到存储过程'登录名'” )。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM