namespace 检查插件
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }        private void Form1_Load(object sender, EventArgs e)
        {
           
        }
        DataSet myDataSet = new DataSet();
        private void button1_Click(object sender, EventArgs e)
        {
            
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "xls|*.xls";            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                myDataSet = new DataSet();                //加载SectorType&OOIP&Wellpattern       
                GetConnect(ofd.FileName, "采油井月数据1");
                dataGridView1.DataMember = "采油井月数据1";
                dataGridView1.DataSource = myDataSet;
            }
        }
private void GetConnect(string sURL, string sSheetName)
        {
            //创建一个数据链接
            string strCon = string.Format(@" Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = {0};Extended Properties=Excel 8.0", sURL);
            OleDbConnection myConn = new OleDbConnection(strCon);
            string strCom = string.Format(@" SELECT * FROM [{0}$] ", sSheetName);
            myConn.Open();
            //打开数据链接,得到一个数据集
            OleDbDataAdapter myCommand = new OleDbDataAdapter(strCom, myConn);
            //得到自己的DataSet对象
            myCommand.Fill(myDataSet, sSheetName);
            //关闭此数据链接
            myConn.Close();
        }private void button2_Click(object sender, EventArgs e)
{
    DataGridViewTextBoxColumn 检查 = new DataGridViewTextBoxColumn();
    检查.Name = "检查";
    检查.DataPropertyName = "检查";
    检查.HeaderText = "检查";
    dataGridView1.Columns.Add(检查);
    for (int i = 0; i < dataGridView1.Rows.Count; i++)
    {
        if ([color=#FFFF00]dataGridView1.Rows[i]["生产天数"] * dataGridView1.Rows[i]["日产油量"] = dataGridView1.Rows[i]["月产油量"])
        {
            dataGridView1.Rows[i]["检查"] = "";
        }
        else
        {
            dataGridView1.Rows[i]["检查"] = "注意";
        }
    }
}    }
}
问题在最后for循环中dataGridView1.Rows[i]["生产天数"]这一块

解决方案 »

  1.   

    类型转换一下:Convert.ToInt32(dataGridView1.Rows[i]["生产天数"].ToString())其它的类似,另外,= dataGridView1.Rows[i]["月产油量"],判断是否相等用==
      

  2.   

    if ([color=#FFFF00]dataGridView1.Rows[i]["生产天数"] * dataGridView1.Rows[i]["日产油量"] = dataGridView1.Rows[i]["月产油量"]) 
    这个判断用==号,赋值才会用=号
      

  3.   

    dataGridView1.Rows[i]["生产天数"].value
      

  4.   

    然后他这报错说运算符无法应用于object和object类型的操作数。。这怎么办。。
      

  5.   

    dataGridView1.Rows[0].Cells[列号].Value = 值;见 如何:操作 Windows 窗体 DataGridView 控件中的行
      

  6.   

    Convert.ToInt32(dataGridView1.Rows[i]["生产天数"].Value.ToString())这里可能有个Value属性,试一下。
      

  7.   

    试了,然后就报错说运算符*无法应用于string和string类型的操作数
      

  8.   

    试了,然后就报错说运算符*无法应用于string和string类型的操作数
    你要把String转换成INT
      

  9.   

    Convert.ToInt32(这个转换加了吗
      

  10.   

      if (Convert.ToInt32(dataGridView1.Rows[i]["生产天数"].Value.ToString())*Convert.ToInt32( dataGridView1.Rows[i]["日产油量"].Value.ToString()) == Convert.ToInt32( dataGridView1.Rows[i]["月产油量"].Value.ToString()))
      

  11.   

    int dateNum = 0;
    if (!dataGridView1.Rows[i]["生产天数"].Value.ToString().equals(""))
    {
         dateNum = Convert.ToInt32(dataGridView1.Rows[i]["生产天数"].Value.ToString());
    }
    最好有这样的判断!
      

  12.   

    是数值。。但是有小数,也有0,我改成了decimal类型也不行。。不知道用什么类型了。。
      

  13.   


    首先这里就错了,然后验证非空if(!string.IsNullOrEmpty(dataGridView1.Rows[i]["生产天数"])&&!string.IsNullOrEmpty(dataGridView1.Rows[i]["日产油量"])&&!string.IsNullOrEmpty(dataGridView1.Rows[i]["月产油量"])){
    //todo.....  这边就是进行数据转换了
    }else{
                dataGridView1.Rows[i]["检查"] = "注意";
    }