Hi everyone;
I'm working on a c# service that queries the DB and checks if the right info is available for users. It's an Airline tickets reservation system.
I am not sure why my code is breaking after it gets the query and it gives an error about sqlclient..
This is the error message I get.....
System.Data.SqlClient.SqlException: Incorrect syntax near '.'. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) at System.Data.SqlClient.SqlDataReader.ConsumeMetaData() at System.Data.SqlClient.SqlDataReader.get_MetaData() at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet) at WebService1.Service1.flightSearch(String depAirport, String arrAirport, String depDate, Int32 numOfSeats)
[WebMethod]
public string flightSearch(string depAirport, string arrAirport, string depDate, int numOfSeats)
{
SqlConnection conn = new SqlConnection(connString);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
//int result = 0;
try
{
conn.Open();
string query = "SELECT departure_date, airport_location, seat_capacity, origin_airport_code, destination_airport_code FROM Flight_Schedule, Airport, Travel_Class_Capacity";
query += "WHERE airport_location.Airport= '" + arrAirport + "' AND airport_location.Airport='" + depAirport + "' AND departure_date.Flight_Schedule='" + depDate + "' AND ";
query += "seat_capacity.Travel_Class_Capacity ='"+numOfSeats+"' AND seat_capacity.Travel_Class_Capacity > 0";
SqlCommand cmd = new SqlCommand(query, conn);
da.SelectCommand = new SqlCommand(query,conn);
da.Fill(ds);
if (ds.Tables[0].Rows.Count <=0)
{
return true;
}
conn.Close();
}
catch (Exception ex)
{
conn.Close();
}
return false;
the compiler gets up to da.Fill(ds) then jumps to the Catch Exception part. So, the idea is if this flightSearch method == true then I want to pass it to the next method(review) to display the info of the flights
[WebMethod]
public string review() // pass something to see if flightSearch == true (But not sure how to do this, I can't pass a new instance of the flightSearch method, Can I? )
{
SqlConnection conn = new SqlConnection(connString);
try
{
conn.Open();
string query = "SELECT flight_number, airline_code, departure_date, arrival_date, departure_airport, arrival_airport,type, seat_capacity travel_class_code FROM Aircraft_Type, Travel_Class_Capacity, Flight_Schedule_Seat_Price";
query += " WHERE travel_class_code='F' AND travel_class_code='B' AND travel_class_code='E' ";
}
catch (Exception) { conn.Close(); }
return someInfo;
Your help is appreciated so much. Hope to hear from someone really soon. THANKS in advance.