无法将类型'double'隐式转换为'double []' [英] Cannot implicitly convert type 'double' to 'double[]'

查看:352
本文介绍了无法将类型'double'隐式转换为'double []'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  protected   void  btnSubmit_Click(对象发​​件人,EventArgs e)
{
string connectionString = ;
if (FileUpload1.HasFile)
{
string fileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
string fileExtension = Path.GetExtension(FileUpload1.PostedFile.FileName);
string fileLocation = Server.MapPath( 〜/ App_Data / + fileName);
FileUpload1.SaveAs(fileLocation);
if (fileExtension == 。xls
{
connectionString = Provider = Microsoft.Jet.OLEDB。 4.0;数据源= + fileLocation + ;扩展属性= \Excel 8.0; HDR =是; IMEX = 2\ ;
}
else if (fileExtension == 。xlsx
{
connectionString = Provider = Microsoft.ACE.OLEDB.12.0; Data Source = + fileLocation + ;扩展属性= \Excel 12.0; HDR =是; IMEX = 2 \;
}
OleDbConnection con = new OleDbConnection(connectionString);
OleDbCommand cmd = new OleDbCommand();
ArrayList List = new ArrayList();
cmd.CommandType = System.Data.CommandType.Text;
cmd.Connection = con;
OleDbDataAdapter dAdapter = new OleDbDataAdapter(cmd);
DataTable dtExcelRecords = new DataTable();
con.Open();
DataTable dtExcelSheetName = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null );
string getExcelSheetName = dtExcelSheetName.Rows [ 0 ] [ Table_Name]。ToString();
cmd.CommandText = SELECT * FROM [ + getExcelSheetName + ];
dAdapter.SelectCommand = cmd;
dAdapter.Fill(dtExcelRecords);
if (会话[ dtInSession]!= null
{
dt =(DataTable)Session [ dtInSession];
}
for int i = 0 ; i < dtExcelRecords.Rows.Count; i ++)
{
int 结果;
// 如果你想得到字符串
DataRow thisRow =(DataRow )dtExcelRecords.Rows [I];
double [] X = Convert.ToDouble(thisRow [ Y]);
double [] Y = Convert.ToDouble(thisRow [ X]);
}

解决方案

替换下面的行...

  double  [] X = Convert.ToDouble(thisRow [  Y]); 
double [] Y = Convert.ToDouble(thisRow [ X]);



with

  double  X = Convert.ToDouble(thisRow [  Y] ); 
double Y = Convert.ToDouble(thisRow [ X]);


protected void btnSubmit_Click(object sender, EventArgs e)
{
    string connectionString = "";
    if (FileUpload1.HasFile)
    {
        string fileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
        string fileExtension = Path.GetExtension(FileUpload1.PostedFile.FileName);
        string fileLocation = Server.MapPath("~/App_Data/" + fileName);
        FileUpload1.SaveAs(fileLocation);
        if (fileExtension == ".xls")
        {
            connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\"";
        }
        else if (fileExtension == ".xlsx")
        {
            connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";
        }
        OleDbConnection con = new OleDbConnection(connectionString);
        OleDbCommand cmd = new OleDbCommand();
        ArrayList List = new ArrayList();
        cmd.CommandType = System.Data.CommandType.Text;
        cmd.Connection = con;
        OleDbDataAdapter dAdapter = new OleDbDataAdapter(cmd);
        DataTable dtExcelRecords = new DataTable();
        con.Open();
        DataTable dtExcelSheetName = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
        string getExcelSheetName = dtExcelSheetName.Rows[0]["Table_Name"].ToString();
        cmd.CommandText = "SELECT * FROM [" + getExcelSheetName + "]";
        dAdapter.SelectCommand = cmd;
        dAdapter.Fill(dtExcelRecords);
        if (Session["dtInSession"] != null)
        {
            dt = (DataTable)Session["dtInSession"];
        }
        for (int i = 0; i < dtExcelRecords.Rows.Count; i++)
        {
           int result;
            //if you want to get the string
          DataRow thisRow = (DataRow)dtExcelRecords.Rows[i];
          double[] X = Convert.ToDouble(thisRow["Y"]);
          double[] Y = Convert.ToDouble(thisRow["X"]);   
        }

解决方案

Replace below lines...

double[] X = Convert.ToDouble(thisRow["Y"]);
double[] Y = Convert.ToDouble(thisRow["X"]);


with

double X = Convert.ToDouble(thisRow["Y"]);
double Y = Convert.ToDouble(thisRow["X"]); 


这篇关于无法将类型'double'隐式转换为'double []'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆