I Have been looking at this for 2 hours where is this incorrect syntax!?
Here is the line the error happens
https://i.stack.imgur.com/08tGY.png
public static class InvestorProcessor
{
public static int CreateInvestment(int id, string tickerSymbol, Sale transactionType, string companyName, int quantity, int sharePrice)
{
Investor data = new Investor
{
Id = id,
TickerSymbol = tickerSymbol,
TransactionType = transactionType,
CompanyName = companyName,
Quantity = quantity,
SharePrice = sharePrice
};
string sql = @"insert into DB.Transaction (TickerSymbol, TransactionType, CompanyName, Quantity, SharePrice)
values (@TickerSymbol, @TransactionType, @CompanyName, @Quantity, @SharePrice);";
return SqlDataAccess.SaveData(sql, data);
}
public static List<Investor> LoadInvestors()
{
string sql = @"select Id, TickerSymbol, TransactionType, CompanyName, Quantity, SharePrice
from DB.Transaction;";
return SqlDataAccess.LoadData<Investor>(sql);
}
}
}
2
Answers
You should try without
DB.
and check data types:If the error persists, try to take the query into SQL Server Management Studio. You have more details there.
TRANSACTION
is a T-SQL reserved keyword. If you want to have it as an object name (and generally you should avoid using reserved keywords as object names), as the docs say (my emphasis):This fails, with the same error you are getting:
this succeeds: