CommandText property has not been initialized
HejsaJeg får fejlen "CommandText property has not been initialized", når jeg prøver at hente data fra min SQL server.
Koden:
public List<Branch> BranchSelectByUser(int id)
{
List<Branch> colBranchUsers = new List<Branch>();
SqlConnection con = new SqlConnection(_connectionString);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
using (con)
{
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
cmd.CommandText = "SELECT b.description, From branch_user bu, Branchs b, users u where b.id = bu.id and bu.userid = u.id and u.id =1";
while (reader.Read())
{
colBranchUsers.Add(new Branch((int)reader["id"],
(string)reader["description"],
(string)reader["contact"]));
}
}
con.Close();
return colBranchUsers;
}