Answer the question
In order to leave comments, you need to log in
ConnectionString property not initialized how to fix?
decided to connect to the database through the class and, as usual, new errors System.InvalidOperationException: "ExecuteScalar needs an open and available connection Connection. The connection is closed."
using (Connction.sqlConnection)
{
SqlCommand sqlCommand = new SqlCommand("SELECT Key_num FROM Users WHERE Phone = @Phone", Connction.sqlConnection);
sqlCommand.Parameters.AddWithValue("@Phone", phone);
return (int?)sqlCommand.ExecuteScalar();
}
public static class Connction
{
public static SqlConnection sqlConnection = new SqlConnection(@"Data Source = (LocalDB)\MSSQLLocalDB; AttachDbFilename=D:\MDK\MDK\MDK\DB.mdf;Integrated Security = True");
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question