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 8933089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:27:21+00:00 2026-06-15T09:27:21+00:00

this code wont run it supposed to fill the datagridview some data but all

  • 0

this code wont run it supposed to fill the datagridview some data but all i got was the rows of how many data was retrieve but no values on each cells

    public void refDGV()
    {

        con.OpenConnections();
        SqlCommand cmd = new SqlCommand();
        SqlConnection cn = new SqlConnection();
        SqlDataAdapter da = new SqlDataAdapter();
        DataSet ds = new DataSet();
        cmd.Connection = cn;
        cmd.CommandType = CommandType.Text;
        cn.ConnectionString = con.connections1;
        cmd.CommandText = "Select  dtransdate, ntotal_pass, nincomeday, ndiesel_exp,  nstartkm, nendkm  from ROUTE2 where ccontrol_no = '" +txtCN.Text + "'";
        da = new SqlDataAdapter();
        da.SelectCommand = cmd;
        ds = new DataSet();
        da.Fill(ds, "Data");
        dgroute.DataSource = ds;
        dgroute.DataMember = "Data";
       dgroute.Columns[0].HeaderText = "Date";
       dgroute.Columns[1].HeaderText = "Total Passenger";
       dgroute.Columns[2].HeaderText = "Income Day";
       dgroute.Columns[3].HeaderText = "Diesel (w/ reciept)";
       dgroute.Columns[4].HeaderText = "Start";
       dgroute.Columns[5].HeaderText = "End";




    }
  • 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-15T09:27:23+00:00Added an answer on June 15, 2026 at 9:27 am

    you could always make a DataBase Class and if you need to refactor this Class to pass in Connection String or read Connection string from .Config File you can use this as a template to get started plus it’s a lot cleaner
    Notice that I am returning a DataTable you can use this if you like just a suggestion

    public class ClassDataManagement 
    { 
       public DataTable GetData(string sqlcmdString, string connString)
       {
           SqlConnection con = new SqlConnection(connString);
           SqlCommand cmd = new SqlCommand(sqlcmdString, cn);
           SqlDataAdapter da = new SqlDataAdapter(cmd);
           con.Open();
           DataTable dt = new DataTable();
           da.Fill(dt);
           return dt;
       } 
    }
    

    if you want to use DataSet instead of DataTable replace where i have DataTable with
    or change the method to return a DataSet like this below

       public DataSet GetData(string sqlcmdString, string connString)
       {
           SqlConnection con = new SqlConnection(connString);
           SqlCommand cmd = new SqlCommand(sqlcmdString, cn);
           SqlDataAdapter da = new SqlDataAdapter(cmd);
           con.Open();
           DataSet ds = new DataSet();
           da.Fill(ds);
           return ds;
       }   
    

    after returning the ds you will need to bind it like this

       dgroute.DataSource = ds;
       dgroute.DataBind();
    

    also for you dgroute Header I think the code should read like this when assigning Data to the ColumnHeader

       dgroute.Rows[0].Column["Heading"] = "Date";
       dgroute.Rows[1].Column["Heading"] = "Total Passenger";
       dgroute.Rows[2].Column["Heading"] = "Income Day";
       dgroute.Rows[3].Column["Heading"] = "Diesel (w/ reciept)";
       dgroute.Rows[4].Column["Heading"] = "Start";
       dgroute.Rows[5].Column["Heading"] = "End";
    

    **Refactor your Sql Select Statement as well to allow for Parameters you are setting yourself up for SQL Injection just a constructive suggestion

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

Sidebar

Related Questions

for some reason this code wont work, it doesn't seem to read the javascript.php
When building the code it builds fine but wont run. Debugging it causes a
I am trying to use some sample code and my compiler won't compile this
This code below allows me to find the word error in all my files
Ok for some reason my code wont play nice and I'm too new to
Suppose I got this code segment: (defparameter *islands* '((1 9 8 5) (6 4
So I have this bit of code, that for some reason won't compile, because
suppose we have this next sample code: while(some condition){ lock1.lock(); . . } the
I have a <a> element that's supposed to run code and not redirect. here
I am trying to modify DOM elements but for some reason the code gets

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.