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]["生产天数"]这一块
{
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]["生产天数"]这一块
这个判断用==号,赋值才会用=号
你要把String转换成INT
if (!dataGridView1.Rows[i]["生产天数"].Value.ToString().equals(""))
{
dateNum = Convert.ToInt32(dataGridView1.Rows[i]["生产天数"].Value.ToString());
}
最好有这样的判断!
首先这里就错了,然后验证非空if(!string.IsNullOrEmpty(dataGridView1.Rows[i]["生产天数"])&&!string.IsNullOrEmpty(dataGridView1.Rows[i]["日产油量"])&&!string.IsNullOrEmpty(dataGridView1.Rows[i]["月产油量"])){
//todo..... 这边就是进行数据转换了
}else{
dataGridView1.Rows[i]["检查"] = "注意";
}