Advertisement

07.17.2008 at 04:56AM PDT, ID: 23572833
[x]
Attachment Details

DbConnection CreateCommand  Stored Procedure window form

Asked by myebay in .NET, C# Programming Language

Tags: c# wf ado.net

Hello,

I have a function that works but I need to change it in Stored Procedure called "viewAllUsers". Could you tell me what I need to change to make it works?

private List<User> GetUsersFromDB(DbConnection cnx)
        {
            List<User> users = new List<User>();

            using (DbCommand cmd = cnx.CreateCommand())
            {
                cmd.CommandType = System.Data.CommandType.Text;
                cmd.CommandText = "SELECT * FROM UserTable";

                 using (DbDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        User user = new User();
                        user.UserID = reader["UserID"] == DBNull.Value ? default(int) : int.Parse(reader["UserID"].ToString());
                        user.UserName = reader["Name"] == DBNull.Value ? default(string) : reader["Name"].ToString();
                        user.UserPassword = reader["Password"] == DBNull.Value ? default(string) : reader["Password"].ToString();
                        user.UserGender = reader["Gender"] == DBNull.Value ? default(string) : reader["Gender"].ToString();
                        user.UserAge = reader["Age"] == DBNull.Value ? default(int) : int.Parse(reader["Age"].ToString());
                        user.UserGeneral = reader["General"] == DBNull.Value ? default(string) : reader["General"].ToString();
                        user.UserTDI_Type = reader["TDI_Type"] == DBNull.Value ? default(string) : reader["TDI_Type"].ToString();
                        user.UserPhilisophy = reader["Philisophy"] == DBNull.Value ? default(string) : reader["Philisophy"].ToString();
                        user.UserReligion = reader["Religion"] == DBNull.Value ? default(string) : reader["Religion"].ToString();
                        user.UserPolitics = reader["Politics"] == DBNull.Value ? default(string) : reader["Politics"].ToString();
                        user.UserUseFrequency = reader["UseFrequency"] == DBNull.Value ? default(int) : int.Parse(reader["UseFrequency"].ToString());
                        user.UserViewFrequency = reader["ViewFrequency"] == DBNull.Value ? default(int) : int.Parse(reader["ViewFrequency"].ToString());

                        users.Add(user);
                    }
                }
            }
            return users;
        }Start Free Trial
 
Loading Advertisement...
 
[+][-]07.17.2008 at 05:05AM PDT, ID: 22024460

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: .NET, C# Programming Language
Tags: c# wf ado.net
Sign Up Now!
Solution Provided By: molku
Participating Experts: 2
Solution Grade: A
 
 
[+][-]07.17.2008 at 05:15AM PDT, ID: 22024551

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628