Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3345212
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:09:34+00:00 2026-05-18T01:09:34+00:00

At present i have a the following code populating a datagridview showing the user

  • 0

At present i have a the following code populating a datagridview showing the user account information on our system. What i want to do do is have a checkbox on the datagridview for the option “accountenabled” and a update button at the bottom of the form so it will update all users that have had changes made against them. I am currently pulling the data back using an sqldatareader however from what i have read i need to use a sqldataadapter. I`ve created the column names on the datagridview and the reader is currently pulling everything back correctly.

Could someone please point me in the right direction of doing this with an sqldatadapter?

Thanks

public UserAdmin()
    {
        InitializeComponent();

        //Load user list

        // Locals
        Functionality func = new Functionality();
        SqlConnection supportDB = null;
        SqlCommand CheckUser = null;
        SqlDataReader rdr;
        DataSet ds = new DataSet();
        DataTable dt = new DataTable();

        string User = System.Environment.UserName.ToString();
        string spName = "gssp_ShowAllUsers";

        try
        {
            using (supportDB = new SqlConnection(GSCoreFunc.ConnectionDetails.getConnectionString(ConnectionType.SupportDB)))
            {
                using (CheckUser = new SqlCommand(spName, supportDB))
                {
                    // Set the command type
                    CheckUser.CommandType = CommandType.StoredProcedure;

                    // Populate the parameters.
                    CheckUser.Parameters.Add(func.CreateParameter("@spErrorID", SqlDbType.Int, ParameterDirection.Output, DBNull.Value));

                    // Open the connection and populate the reader with the SP output
                    supportDB.Open();
                    rdr = CheckUser.ExecuteReader();
                    if (CheckUser.Parameters["@spErrorID"].Value != null)
                    {
                        throw new InvalidOperationException();
                    }

                    // If the data reader has rows display output on label
                    if (rdr.HasRows)
                    {
                        //Output values
                        while (rdr.Read())
                        {
                            //Bind to data table
                            dgvUsers.Rows.Add(rdr["agentID"].ToString(), rdr["createdon"].ToString(), rdr["firstname"].ToString(), rdr["lastname"].ToString(), rdr["username"].ToString(), rdr["emailaddress"].ToString(), rdr["Departments"].ToString(), rdr["accountenabled"].ToString(), rdr["AgentAccountLevel"].ToString());
                        }
                    }

                    // Close reader and connection.
                    rdr.Close();
                    supportDB.Close();
                }
            }
        }

        catch (Exception ex)
        {
            //Show error message
            string error = ex.ToString(); //Real error
            string FriendlyError = "There has been error loading the user list"; // Error user will see
            GSCoreFunc.ShowMessageBox.msgBoxErrorShow(FriendlyError);

            //Log error to ExceptionDB
            GSCoreFunc.ReportException.reportEx(GSCoreFunc.ApplicationInformation.ApplicationName, error, FriendlyError, GSCoreFunc.ApplicationInformation.ComputerName, GSCoreFunc.ApplicationInformation.OperatingSystem, GSCoreFunc.ApplicationInformation.screenSize, GSCoreFunc.ApplicationInformation.IPAdddress, GSCoreFunc.ApplicationInformation.domainName);// Pass error to GSCoreFunc to log to the ExceptionDB
        }
    }

    private void btClose_Click(object sender, EventArgs e)
    {
        //Close window
        Close();
    }
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T01:09:35+00:00Added an answer on May 18, 2026 at 1:09 am

    There is nothing wrong with using the SqlDataReader. The SqlDataAdapter is a higher level api that allows you to iterate through an SqlDataReader and store a copy of the results in a DataTable or a DataSet. This copy can then be used as the data source for your DataGridView.

    One thing I would change with your code would be to use data binding instead of generating each row manually. If you set the DataSource property of the grid to either your SqlDataReader or to a DataTable filled by an SqlDataAdapter and then call the grids DataBind() method the grid should be filled automatically with your data.

    To control the columns you would make sure your query only returns the required columns, and you would define the column setup in your aspx-file.

    Using data binding is generally an easier and more flexible approach, so you should consider using that instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Excel application in which I want to present the user with
I have to present some 'process' or 'flow' of the application at work on
I've noticed that a few Wordpress blogs have query statistics present in their footer
Say I have: void Render(void(*Call)()) { D3dDevice->BeginScene(); Call(); D3dDevice->EndScene(); D3dDevice->Present(0,0,0,0); } This is fine
Note: Using MySQL 4.0, which means no subqueries (at present). I have 2 tables:
I have a function that presents the user a combo-box. def select_interface(interfaces) list_box :items
I have some code which utilizes parameterized queries to prevent against injection, but I
I have some formulas in my reports, and to prevent divsion by zero I
How does your employer limit/prevent pirating of its products? Some have the view that
How does one prevent an inclusion cycle in C? ie. You shouldn't have a.h

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.