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

  • Home
  • SEARCH
  • 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 7921823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:43:45+00:00 2026-06-03T16:43:45+00:00

I have a winform which has a gridview that is populating through a stored

  • 0

I have a winform which has a gridview that is populating through a stored procedure the stored procedure is

    ALTER PROCEDURE [dbo].[spGetAllCustumer]

    AS
    SET NOCOUNT ON 
SET XACT_ABORT ON  
    BEGIN TRAN
  BEGIN
SELECT     Customer.CustID, Customer.CustName, Customer.CompanyName, Customer.CompanyRealtion, Contract.ContractID, Contract.ContractDate, 
                  '$'+ CONVERT(varchar,Contract.totalPayment,1), '$'+ CONVERT(varchar,Contract.monthlyInstallment,1), '$'+ CONVERT(varchar,Contract.totalCommission,1), Contract.ContractDuration, Contract.PaymentMode, Contract.Description, 
                  Customer.Disable
FROM         Customer INNER JOIN
                  Contract ON Customer.CustID = Contract.CustID
WHERE     (Customer.Disable = 'false')

 END
commit

and I’m populating the gridview dynamically with this code

    con.ConnectionString = "Data Source=MRDEVELOPER;Initial Catalog=Crystal_Accounts;Integrated Security=True";
            SqlCommand com = new SqlCommand();
            com.Connection = con;
            com.CommandText = "spGetAllCustumer";
            com.CommandType = CommandType.StoredProcedure;
            com.Parameters.Clear();
            con.Open();
            SqlDataReader dr = com.ExecuteReader();
            DataTable dt = new DataTable();
            dt.Load(dr);
            dataGridView1.DataSource = dt;

I want to select the custID, contractID, totalpayment of the selectedRow i don’t know how can i do it and second question is about the currency sign that i used in the storedprocedure is it right way or what is the best way to do that?

  • 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-06-03T16:43:47+00:00Added an answer on June 3, 2026 at 4:43 pm

    As volody pointed out, you can use the SelectedRows property to get everything you need. However, you might not know the indexes of the columns in question (although they’re usually generated in the same order as the query, so make sure to alias the columns properly), you can use the column text itself via string access on the cells:

    foreach(DataGridViewRow row in DataGridView1.SelectedRows)
    {
        // Do something with row.Cells["CustID"].Value;
        // Do something with row.Cells["ContractID"].Value;
        // Do something with row.Cells["TotalPayment"].Value;
    }
    

    The other thing I would suggest you do is to leave the formatting up to the DataGridView instead of the SQL query. This is generally best practice when separating your data access/business logic layer from your presentation/UI layer. The way you would do this would be to specify a DataFormatString on the DataTable’s DataColumn for the columns in question. In this particular case, you would do this:

    ...
    DataTable dt = new DataTable();
    dt.Load(dr);
    dt.Columns["TotalPayment"].DataFormatString = "C";
    dt.Columns["MonthlyInstallment"].DataFormatString = "C";
    dt.Columns["TotalCommission"].DataFormatString = "C";
    dataGridView1.DataSource = dt;
    

    The downside to doing everything in code is that you don’t get any design-time support, meaning you have to test everything out during run-time (which could be time consuming). That’s one of the reasons ORM’s are used (such as the VS DataSet Designer, LINQ2SQL designer, EntityFramework, etc), so that you have design-time support of database queries/objects. It makes it even easier to bind these data classes directly to UI controls at design-time and determine everything about the presentation layer before even running the code (such as which columns will be hidden, any additional computed columns, special column formatting, conditional row/column/cell painting, etc).

    Just my $0.02 worth.

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

Sidebar

Related Questions

I have a Winform app that has 16 SQL Connections currently stored in the
I have a winform form which has typical OK and Cancel buttons. The OK
I have a Winform app which lists a batch of invoices in a gridview.
I have a parent WinForm that has a MyDataTable _dt as a member. The
I have a Winform DataGridView , which has a number of predefined columns. Now
I have a User Control that has some WinForm Controls inside. I want to
i have this situation, i have a winform which has arround 10 to 15
I have a userControl11 (either in winform or wpf) which has a ValueChanged custom
I have WinForm which is a tab based and including all Tabs it has
I have a Winform app that has a backgroundWorker thread and does all operations

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.