X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
   Reply to this topicStart new topic
> Cannot Implicitly Convert 'object' To 'string'    
post May 22 2014, 05:24 PM

Posts: 433
Joined: 13-April 04

In one bit of code I have these variables declared.
string oSalesOrder = oROW.Cells[4].Value.ToString();
string oLineItem = oROW.Cells[5].Value.ToString();

Later on in the code I pass these variables to ContentReport.
ContentReport oSBXContent = new ContentReport(oSalesOrder,oLineItem);

When I get to the last line of the code below, I get the ol' "Cannot implicitly convert 'object' to 'string'. An explicit conversion exists (are you missing a cast?)" error.
It's driving me mad! I've been looking online to learn about the error, but I still don't see where an explicit conversion needs to take place.
public class ContentReport
    public string CustomerString { get; set; }
    public ContentReport(string oSalesOrder, string oLineItem)
        // Read the Content Report raw data file. Each newline signifies a new record. Generates a raw string that contains the data.
        string oLine;
        string oProgramsRAW = "";
        System.IO.StreamReader file = new System.IO.StreamReader(Application.StartupPath.ToString() + @"\DOWNLOADS\" + oSalesOrder + "_" + oLineItem + ".txt");
        while ((oLine = file.ReadLine()) != null)
            if (oLine.ToString() != "")
                oProgramsRAW += oLine.ToString() + "|";
        //Create a 3D array based off the string.
        string[] oProgramsRAWArray = oProgramsRAW.Split(new char[] { '|' });
        string oMaterial = "";
        string oMaterial_Desc = "";
        string oDVDNumber = "";
        int oCounter = 0;
        //Queries the ZP_Sched table in order to identify and capture the customer name for use on the report.
        //SBX_Downloader.MASTER_BACK_ENDDataSetTableAdapters.tbl_vw_ZPSchedTableAdapter tableAdapter = new SBX_Downloader.MASTER_BACK_ENDDataSetTableAdapters.tbl_vw_ZPSchedTableAdapter();
        //string oCustomer = tableAdapter.Customer_Name(oSalesOrder, oLineItem);
        SBX_Downloader.MillenniumDataSetTableAdapters.tbl_ZPSchedTableAdapter tableAdapter = new SBX_Downloader.MillenniumDataSetTableAdapters.tbl_ZPSchedTableAdapter();
        string oCustomer = tableAdapter.Customer_Name(oSalesOrder);
Go to the top of the page
post May 22 2014, 06:18 PM

UtterAccess Editor
Posts: 9,793
Joined: 7-December 09
From: Staten Island, NY, USA

>> string oCustomer = tableAdapter.Customer_Name(oSalesOrder); <<
The table adapter isn't going to return a string by default... try putting the cast there:
string oCustomer = tableAdapter.Customer_Name(oSalesOrder) as string;
// or
string oCustomer = (string)tableAdapter.Customer_Name(oSalesOrder);
Go to the top of the page
post May 23 2014, 11:36 AM

Posts: 433
Joined: 13-April 04

Jack! That worked perfectly. Thanks a bunch.
Go to the top of the page

Custom Search
RSSSearch   Top   Lo-Fi    11th December 2017 - 04:20 AM