Some C# problems

Discussion in 'Software' started by Burning_Monkey, Aug 29, 2006.

  1. Burning_Monkey

    Burning_Monkey MajorGeek

    This is some what embarassing, but I am tired of trying to figure it out.

    I have a data table on a SQLServer machine and I want to populate a combobox with some of that data.

    So far I have gotten this;
    Code:
    SqlConnection conn = new SqlConnection("server=127.0.0.1;uid=sa;password=;database=hotscale");
    DataSet carrierSet = new  DataSet();
    conn.Open();
    SqlDataAdapter carrierSqlAdapter = new SqlDataAdapter("SELECT vendorID AS ID, CAST(vendorID AS varchar) + ' ' + strCompany AS Name FROM Master WHERE (strVenType = 'F') OR (strVenType = 'D') OR (strVenType = 'T') ORDER BY strCompany",conn);
    SqlCommandBuilder carrierSqlBuilder = new SqlCommandBuilder(carrierSqlAdapter);			carrierSqlAdapter.TableMappings.Add("Table","carrierTable");
    carrierSqlAdapter.Fill(carrierSet,"carrierTable");
    conn.Close();
    carrierComboBox.DataSource = carrierSet;
    carrierComboBox.DisplayMember = "Name";
    
    But out of that all I get is;
    Code:
    System.Data.DataViewManagerListItemTypeDescriptor
    
    in my combobox.

    What am I doing wrong?
     
  2. Kodo

    Kodo SNATCHSQUATCH

    carrierComboBox.DataSource=carrierSet.tables["carrierTable"].defaultView;
     
  3. matt.chugg

    matt.chugg MajorGeek

    I suspect you have the column name wrong.

    carrierComboBox.DisplayMember = "Name";

    try

    carrierComboBox.DisplayMember = carrierSet.tables("carrierTable").Columns(0)


    I could of course be entirely wrong lol ;)
     
  4. matt.chugg

    matt.chugg MajorGeek

    To be fair i'd go with whatever kodo says lol

    Was posting but session ended and kodo posted while I was logging in again lol
     
  5. Kodo

    Kodo SNATCHSQUATCH

    that's putting an awful lot of confidence in me :)

    An additional note.
    If you're only populating one table and you're using a dataset and you won't be adding any other tables to the dataset, then use a DataTable instead of a DataSet.
     
    Last edited: Aug 29, 2006
  6. matt.chugg

    matt.chugg MajorGeek

    heh outside of the standard oledb stuff my db knowledge is pretty limited, I've only ever used the standard executescalar and executereader stuff. I don't think i've ever populated a dataset or datatable! So I think the odds are in your favour!
     
  7. Burning_Monkey

    Burning_Monkey MajorGeek

    Thank you very much.

    And for future reference it is;
    carrierComboBox.DataSource=carrierSet.tables["carrierTable"]
    with out the defaultview on the end. Now I just need to get the type ahead going and I will be golden. :)
     
  8. Burning_Monkey

    Burning_Monkey MajorGeek

    How would I go about selecting the needed data from my database and then populating a DataTable?

    The only reason I chose a DataSet is that I found how to do the steps from SQL Server db to combobox pretty quick. If using a DataTable for my comboboxs will be easier in the long run, I would rather do that.
     
  9. Burning_Monkey

    Burning_Monkey MajorGeek

    Never mind guys, I figured it out. And you were way right, a datatable is a far better way to go in this case.
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds