私はこれをすべて間違っているかもしれませんが、ここに行きます:
    OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM [CRPRList$]", XLSConnect);
    //the XLSConnect is from a spreadsheet. I've confirmed the data is there.
    DataSet ds = new DataSet();
    adapter.Fill(ds);
    DataTable thisTable = ds.Tables[0];
    //The table exists and it does populate
    thisTable.Columns.Add("Summary");
    //The new column is added and I am able to populate it (below)
    for (int rowNum = 0; rowNum < thisTable.Rows.Count; rowNum++) { 
        //Here I'm cycling through the row items
        DataRow row = thisTable.Rows[rowNum];
        string pr = row["PR"].ToString();
        string cr = row["CR"].ToString();
        //The first two column values are grabbed and examined
        if ((pr != "" && pr != null)&&(cr == null || cr == "")) {
           //if the first column is empty then the second is examined and I am attempting
           //to populate the first column using the searchForCRNumber method
           //This method returns a string
            cr = this.searchForCRNumber(pr); //assignment works
            row[0] = cr; //Here is the problem, this assignment does not work (more explained below)
        }
        row["Summary"] = this.searchForSummary(cr);
        row.AcceptChanges();
    }
    this.showResults(thisTable);//works, except the changes above are not applied
行row[0] = cr;は当然空の値であるため、型として表示され、文字列DBNullを受け入れません  cr。
私が得ているエラーはSystem.FormatException: Input string was not in a correct format. 
row[0]空の文字列に変換する方法や、キャストする他の方法を探しましcrたが、これを行う方法はまだ見つかりません。
編集 この問題の周りで何が起こっているのかを理解するのに役立つように、さらに追加しています。私は上記で十分に徹底していると思っていましたが、おそらくそうではありません...
のデータは次のXLSConnectものから取得されます。
private bool XSLConnection(string filePath, string fileType) { // returns false if XSL or XSLX is not the fileType
    string strConn;
    if (fileType.ToLower() == "xls" || fileType.ToLower() == "xlsx") {
        strConn = (fileType == "xlsx") ? string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=\"Excel 12.0\"", filePath) : string.Format("Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=\"Excel 8.0\"", filePath);
        XLSConnect = new OleDbConnection(strConn);
        return true;
    } else return false;
}
searchForCRNumberメソッドは次のとおりです。
private string searchForCRNumber(string PRNumber) {
    return this.getProperty("MyReturnColumn", PRNumber, "MyMatchColumn");
}
そして、ここにgetProperty方法があります:
private string getProperty(string searchProperty, string searchVal, string rtrnProperty) {
    string undefined = "Undefined";
    string rtrn = null;
    string query = "SELECT " + rtrnProperty + " FROM MySQLTable WHERE " + searchProperty + " = '" + searchVal + "'";
    this.QCConn.Open();
    SqlDataReader reader = this.runQCConnect(query).ExecuteReader();
    reader.Read();
    rtrn = (!reader.HasRows)?
        undefined :
        reader[0].ToString();
    if (rtrn == "" || rtrn == null) rtrn = undefined;
    this.QCConn.Close();
    return rtrn;
}
もっと編集 私はまだこれに取り組んでいますが、バグを見つけていないのではないかと思い始めています。私は何が間違っているのかを発見し、まだそれを修正する方法に取り組んでいます. アップロードされた xls(x) には空のセルが含まれる場合があります。これらの空のセルにより、DataTable に空のセルが含まれることがわかりましたが、そのタイプは DBNull です...もちろん、(当然のことながら) 文字列値を割り当てることはできません。
try/catch で以下を適用すると:
throw new Exception("PR = " + pr + " and typeof = " + pr.GetType().ToString() + " && CR = " + cr + " and typeof = " + cr.GetType().ToString() + "\nCell typeof = " + row["CR"].GetType().ToString());
私はこの応答を受け取ります:
PR = 7800 and typeof = System.String && CR = Undefined and typeof = System.String
Cell typeof = System.DBNull 
ご覧のとおり、セルは System.DBNull であり、文字列値を受け入れません。これが私のエラーの原因です。しかし、私はまだこれを機能させる方法を知りません。足りないものはありますか?DBNull 値に関係なく、これらのセルに文字列値を割り当てるにはどうすればよいですか?