Results 1 to 8 of 8

Thread: [RESOLVED] Db question:am I missing something?

  1. #1

    Thread Starter
    Fanatic Member Crash893's Avatar
    Join Date
    Dec 2005
    Posts
    930

    Resolved [RESOLVED] Db question:am I missing something?

    Hi all

    I seem to have everything working but I just cant get my DGV to load

    I think I might be missing something but I'm not sure



    c# Code:
    1. DataSet ds = new DataSet();
    2.             SqlConnection conn = new SqlConnection("Server=gci-mocsqdb01;Database=mdb_rpt;Uid=caiahd_rpt;Pwd=dashboard;");//Driver={SQL Server};
    3.             String SelectCmdString = "select * from gci_requests where (gci_requests.group_name='USAT-Publishing Solutions')";
    4.             SqlDataAdapter da = new SqlDataAdapter(SelectCmdString, conn);
    5.             da.Fill(ds, "gci_requests");
    6.             MessageBox.Show("done loading");
    7.             dataGridView1.DataSource = ds;

    Thanks for takeing a look

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: Db question:am I missing something?

    use
    Code:
    da.Fill(ds);
    Because the Table resulting from the Select statement has no name
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  3. #3

    Thread Starter
    Fanatic Member Crash893's Avatar
    Join Date
    Dec 2005
    Posts
    930

    Re: Db question:am I missing something?

    Done but still nothing showing up in the DGV

    is there a way in debug to see if the dataset actually has data in it

    mabey my query sucks or something

  4. #4
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: Db question:am I missing something?

    First you should check that your query is really returning data. Use the SQL profiler to check that the query is being executed and then check the results.

    You can use a break point after the "Fill" call and check if the dataset has tables and data in it
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Db question:am I missing something?

    You should ALWAYS specify the name of Datatable you're populating. This:
    C# Code:
    1. da.Fill(ds);
    is legal but this:
    C# Code:
    1. da.Fill(ds, "gci_requests");
    is much better.

    If you're going to assign the DataSet itself to the grid's DataSource then you need to set its DataMember too; specifically to the name of the DataTable. Because you did the right thing and specified a name when you populated it then it's simply:
    C# Code:
    1. dataGridView1.DataMember = "gci_requests";
    2. dataGridView1.DataSource = ds;
    Alternatively you could assign the DataTable itself to the DataSource.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Fanatic Member Crash893's Avatar
    Join Date
    Dec 2005
    Posts
    930

    Re: Db question:am I missing something?

    Quote Originally Posted by jmcilhinney
    Alternatively you could assign the DataTable itself to the DataSource.

    thanks for the help

    I will try it out when i get to work tomorrow



    if you have time could you expaned the dataTable part more im not sure exactly what you mean

    thanks

  7. #7

    Thread Starter
    Fanatic Member Crash893's Avatar
    Join Date
    Dec 2005
    Posts
    930

    Re: Db question:am I missing something?

    Well i did the above and still no dice

    The dataset is null so i dont think that its picking up any data from the query

    the weird thing is that i just did a select * from gci_requests

    and the network addapter is showing activity and the cpu is up around 50-60% so its doing something

  8. #8

    Thread Starter
    Fanatic Member Crash893's Avatar
    Join Date
    Dec 2005
    Posts
    930

    Re: Db question:am I missing something?

    Never mind it was the query that was off

    thanks for your help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width