Reputation: 16062
I find this weird, i have this code :
string getBatchesQuery = "SELECT DISTINCT CONVERT(VARCHAR(8), time, 4) AS Batch FROM Calls ORDER BY Batch";
SqlCommand getBatchesQueryCom = new SqlCommand(getBatchesQuery, connection);
SqlDataReader getBatchesQueryReader = myCom.ExecuteReader();
List<string> allBatches = new List<string>();
while (getBatchesQueryReader.Read())
{
allBatches.Add(getBatchesQueryReader["Batch"].ToString());
}
getBatchesQueryReader.Close();
Now how could that be that Batch
doesn't exist? maybe because i name it like that?
What should i do?
Upvotes: 2
Views: 79
Reputation: 838216
The column doesn't exist because you are running the wrong command. Change myCom
to getBatchesQueryCom
.
SqlDataReader getBatchesQueryReader = getBatchesQueryCom.ExecuteReader();
Upvotes: 2