A
A
Artem Nim2017-07-15 21:04:56
SQL
Artem Nim, 2017-07-15 21:04:56

Problem when reading data from database?

When reading data from the database, it gave an error:
2c3804e6e0c248d28ae47f751dcc7b92.jpg
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);
            }
        }

The table itself:
6eca8db5151442dbaeb1732714f0f69c.jpg
Help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Ananiev, 2017-07-15
@SaNNy32

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 question

Ask a Question

731 491 924 answers to any question