i'm getting this error Incorrect syntax near 'LoginName'. in 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;
}
You have to specify CommandType = CommandType.StoredProcedure
(default is Text
):
sqlCom.CommandText = stored_Procedure; // name of stored-Procedure;
sqlCom.CommandType = CommandType.StoredProcedure;
The reason for your issue was that your connection string didn't target the right database. Then the stored-procedure can't be found( "Could not find stored procedure 'Login Name'" ).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.