Answer the question
In order to leave comments, you need to log in
Problem when reading data from database?
When reading data from the database, it gave an error:
For some reason, the values \u200b\u200bare not written to the variables (null everywhere).
The code:
public static void Online_Authorize(out List<User> user_list, User user)
{
user_list = new List<User>();
string ConnectionSting = @"Data Source=.\MSSQLSERVER1;Initial Catalog=OrginizerDB;Integrated Security=True";
string CommandText = "SELECT * FROM Users";
try
{
using (SqlConnection connection = new SqlConnection(ConnectionSting))
{
connection.Open();
SqlCommand cmd = new SqlCommand(CommandText,connection);
SqlDataReader reader = cmd.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read())
{
Parse(reader, out user_list);
}
}
}
AuthorizeM(user_list, user);
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
}
static void Parse(SqlDataReader reader, out List<User> user_list)
{
user_list = new List<User>();
for (int i = 0;i< reader.FieldCount;i++)
{
string[]Name = reader["Name"] as string[];
string[]Email = reader["Email"] as string[];
string[]Password = reader["Password"] as string[];
User user = new User();
user.name = Name[i];
user.email = Email[i];
user.password = Password[i];
user.islocal = false;
user_list.Add(user);
}
}
Answer the question
In order to leave comments, you need to log in
For some reason, the cycle is by columns and not by the number of rows returned by the query
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question