Reputation: 29
I get an error
System.Data.SqlClient.SqlException: Incorrect syntax near '='
My class is
public void bil()
{
SqlConnection con = new SqlConnection();
con.ConnectionString = (@"Server=DESKTOP-8JJO9NL\SQLEXPRESS;Database=HMS;Trusted_Connection=True");
con.Open();
string sqlquery = "select DATEDIFF(day,arrivaldate,departure) AS TotalDays=@tdays ,(DATEDIFF(day,arrivaldate,departure) * 10) AS CalculatedAmount=@amount from Roomsdata where room#=@roomnum2";
SqlCommand command = new SqlCommand(sqlquery, con);
SqlDataReader sReader;
command.Parameters.Clear();
command.Parameters.AddWithValue("@roomnum2", Roomnum);
sReader = command.ExecuteReader();
while (sReader.Read())
{
Tdays = sReader["TotalDays"].ToString();
Amount = sReader["CalculatedAmount"].ToString();
}
con.Close();
More error details:
Line 142: command.Parameters.Clear();
Line 143: command.Parameters.AddWithValue("@roomnum2", Roomnum);
Line 144: sReader = command.ExecuteReader();
Line 145:
Line 146: while (sReader.Read())
Upvotes: 0
Views: 369