есть такой код
List<string> URL = new List<string>();
char[] splitchar = { '/' };
string[] URL_cut = request.RawUrl.Split(splitchar);
for (int count = 0; count <= URL_cut.Length - 1; count++)
{
URL.Add(URL_cut[count]);
}
public static void GetDataSql(List<string> URL)
{
SqlDataReader sqlDataReader = null;
SqlCommand command = new SqlCommand("SELECT id FROM class WHERE class = @class", sqlConnection);
sqlDataReader = command.ExecuteReader();
while (sqlDataReader.Read())
{
Console.WriteLine($"{sqlDataReader["id"]}");
}
}
Почему то он выдает такую ошибку
Unhandled exception. System.InvalidOperationException: ExecuteReader: Connection property has not been initialized.
at Microsoft.Data.SqlClient.SqlCommand.ValidateCommand(Boolean isAsync, String method)
at Microsoft.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry, String method)
at Microsoft.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at Microsoft.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior)
at Microsoft.Data.SqlClient.SqlCommand.ExecuteReader()
at sch121_project_api.methods.GetDataSql(List`1 URL) in C:\Users\Andrew\source\repos\sch121_project_api\sch121_project_api\methods.cs:line 51
at sch121_project_api.Program.Main(String[] args) in C:\Users\Andrew\source\repos\sch121_project_api\sch121_project_api\Program.cs:line 51
at sch121_project_api.Program.<Main>(String[] args)