I have the following code and the datatable only contain one row. I wish to keep the all the data(the one row) value in array. Below is my code:
SqlCommand cmdp = new SqlCommand("SELECT [1],[2],[3],[4],[5],[6],[7].[8],[9],[10],[11],[12],[13],[14],[15],[16],[17],[18],[19],[20],[21],[22],[23],[24],[25],[26],[27],[28],[29],[30],[31],[32],[33],[34],[35],[36],[37],[38],[39],[40],[41],[42],[43],[44],[45],[46],[47],[48],[49],[50],[51],[52],[53],[54],[55],[56],[57],[58],[59],[60],[61],[62],[63],[64],[65],[66],[67],[68],[69],[70],[71],[72],[73],[74],[75],[76],[77],[78] from [Seatlist] where (([FlightNo] = @FN) AND ([Origin] = @Ori) AND ([Destination] = @Des) AND ([DepartureTimeDay] = @Dep) AND ( [DepartureTimeMonths] = @Dem) AND ( [DepartureTimeYears] = @Dey) AND ( [DepartureTime] = @Det))", con);
cmdp.Parameters.AddWithValue("@Seatlist", SeatNo.Text);
cmdp.Parameters.AddWithValue("@FN", FlightNo.Text);
cmdp.Parameters.AddWithValue("@Ori", Origin.Text);
cmdp.Parameters.AddWithValue("@Des", Destination.Text);
cmdp.Parameters.AddWithValue("@Dep", DepartDay.Text);
cmdp.Parameters.AddWithValue("@Dem", DepartMonth.Text);
cmdp.Parameters.AddWithValue("@Dey", DepartureTimeYears.Text);
cmdp.Parameters.AddWithValue("@Det", DepartureTime.Text);
DataTable dtable = new DataTable();
dtable.Load(cmdp.ExecuteReader());
DataRow[] array = dtable.AsEnumerable().Take(1).ToArray();
object[] array1 = array[0].ItemArray;
int[] array2 = Array.ConvertAll(array1, (p => Convert.ToInt32(p)));
But I get the following error:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: The multi-part identifier "7.8" could not be bound.
[7].[8]should probably be[7],[8]. The.in SQL is a multipart identifier - stackoverflow.com/questions/206558/…