none
GraphicID Conversion Type Problems RRS feed

  • Question

  • I am new to c# and am trying to learn with an example and have conquered everything but this. I am being told that "cannot convert type string to integer". I've tried different table settings and  nothing seems to work. Currently the GraphicID is set to image in the tables property. How can I correct this issue. The code in bold is what's giving me the problems.

    Here's the code:

     private void populateDataButton_Click(object sender, EventArgs e)
            {
                this.reportTableAdapter.Fill(this.myExampleDataset.Report);

                sampleListView.Items.Clear();

                sampleListView.BeginUpdate();
           
                foreach(exampleDataset.ReportRow report in myExampleDataset.Report.Rows)
                {
                    ListViewItem reportListItem = new ListViewItem();
                    reportListItem.Text = report.ReportName;
                    reportListItem.Tag = report.ReportID;
                    reportListItem.SubItems.Add(report.Author);
                    reportListItem.SubItems.Add(report.ReportDate.ToShortDateString());
                    reportListItem.ImageIndex = report.GraphicID;
                    reportListItem.Group = sampleListView.Groups[report.ReportGroup];
                    sampleListView.Items.Add(reportListItem);
                }
                sampleListView.EndUpdate();
            }

    Any help would be greatly appreciated, Thanks

    PCRider

    Wednesday, June 4, 2008 12:17 AM

Answers

  • In SQL the Image datatype is a binary datatype, which i think, when converted to C#, comes across as a string.
    http://msdn.microsoft.com/en-us/library/ms187993.aspx

    • Marked as answer by jack 321 Monday, June 9, 2008 2:16 AM
    • Unmarked as answer by PCRider Wednesday, June 18, 2008 5:14 PM
    • Marked as answer by PCRider Tuesday, July 1, 2008 12:00 AM
    Friday, June 6, 2008 4:18 AM

All replies

  • In SQL the Image datatype is a binary datatype, which i think, when converted to C#, comes across as a string.
    http://msdn.microsoft.com/en-us/library/ms187993.aspx

    • Marked as answer by jack 321 Monday, June 9, 2008 2:16 AM
    • Unmarked as answer by PCRider Wednesday, June 18, 2008 5:14 PM
    • Marked as answer by PCRider Tuesday, July 1, 2008 12:00 AM
    Friday, June 6, 2008 4:18 AM
  • Thanks for the reply however, I think i'ts interfering with another code for some reason.
    Here's the code in it's entirety;
    Check the bolded, underlined text somehow this is what's interfering

    private void Main_Load(object sender, EventArgs e)

    {

    // TODO: This line of code loads data into the 'myExampleDataset.Report' table. You can move, or remove it, as needed.

    sampleListView.Columns.Add("Report", 200, HorizontalAlignment.Left);

    sampleListView.Columns.Add("Author", 100, HorizontalAlignment.Left);

    sampleListView.Columns.Add("Report Date", 75, HorizontalAlignment.Center);

    sampleListView.Groups.Add("Report", "Executive Reports");

    sampleListView.Groups.Add("Document", "General Document");

    sampleListView.Groups.Add("Configuration", "Configuration Document");

    sampleListView.View = View.Details;

    sampleListView.AllowColumnReorder = true;

    sampleListView.LabelEdit = true;

    }

    private void reportBindingNavigatorSaveItem_Click(object sender, EventArgs e)

    {

    this.Validate();

    this.reportBindingSource.EndEdit();

    this.tableAdapterManager.UpdateAll(this.myExampleDataset);

    }

    private void populateDataButton_Click(object sender, EventArgs e)

    {

    this.reportTableAdapter.Fill(this.myExampleDataset.Report);

    sampleListView.Items.Clear();

    sampleListView.BeginUpdate();

    foreach(exampleDataset.ReportRow report in myExampleDataset.Report.Rows)

    {

    ListViewItem reportListItem = new ListViewItem();

    reportListItem.Text = report.ReportName;

    reportListItem.Tag = report.ReportID;

    reportListItem.SubItems.Add(report.Author);

    reportListItem.SubItems.Add(report.ReportDate1.ToShortDateString());

    reportListItem.ImageIndex = report.GraphicID;

    reportListItem.Group = sampleListView.Groups[report.ReportGroup];

    sampleListView.Items.Add(reportListItem);

    }

    sampleListView.EndUpdate();

    }

    private void sampleListView_AfterLabelEdit(object sender, LabelEditEventArgs e)

    {

    ListViewItem li;

    li = sampleListView.Items[e.Item];

    //Locate this item in the datatable.

    exampleDataset.ReportRow selectedReportRow;

    selectedReportRow = myExampleDataset.Report.FindByReportID((int)(li.Tag));

    selectedReportRow.ReportName = e.Label;

    int rowsAffected;

    rowsAffected = this.reportTableAdapter.Update(myExampleDataset.Report);

    }

    private void editToolStripMenuItem_Click(object sender, EventArgs e)

    {

    ListViewItem li;

    li = sampleListView.FocusedItem;

    li.BeginEdit();

    }

    }

    }

    Wednesday, June 18, 2008 5:22 PM