自己编写的C#中,运行时存在未将对象引用设置到对象的实例,求如何修改一段
privatevoidcomboBox1_SelectedIndexChanged(objectsender,EventArgse){try{stringsheetNam...
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
string sheetName = comboBox1.Text;
string strCom = @" SELECT * FROM [" + sheetName + "]";
OleDbDataAdapter myCommand = new OleDbDataAdapter(strCom, oledbcConnection);
DataSet myDataSet = new DataSet();
myCommand.Fill(myDataSet, "[" + sheetName + "]");
dataGridView1.DataMember = "[" + sheetName + "]";
dataGridView1.DataSource = myDataSet;
ExcelTable = myDataSet.Tables[sheetName];
int iColums = ExcelTable.Columns.Count;//列数
int iRows = ExcelTable.Rows.Count;//行数
//定义二维数组存储Excel表中读取的数据
float[,] data = new float[iRows, iColums];
for (int i = 0; i < ExcelTable.Rows.Count; i++)
if (ExcelTable.Rows[i][0] != null)
{
for (int j = 0; j < ExcelTable.Columns.Count; j++)
{ //将Excel表中的数据存储到数组
data[i, j] = float.Parse(ExcelTable.Rows[i][j].ToString());
}
}
else
{ break; }
}
catch (Exception exception)
{ MessageBox.Show(exception.Message); }
}
引发异常的语句是程序段里的
int iColums = ExcelTable.Columns.Count; 展开
{
try
{
string sheetName = comboBox1.Text;
string strCom = @" SELECT * FROM [" + sheetName + "]";
OleDbDataAdapter myCommand = new OleDbDataAdapter(strCom, oledbcConnection);
DataSet myDataSet = new DataSet();
myCommand.Fill(myDataSet, "[" + sheetName + "]");
dataGridView1.DataMember = "[" + sheetName + "]";
dataGridView1.DataSource = myDataSet;
ExcelTable = myDataSet.Tables[sheetName];
int iColums = ExcelTable.Columns.Count;//列数
int iRows = ExcelTable.Rows.Count;//行数
//定义二维数组存储Excel表中读取的数据
float[,] data = new float[iRows, iColums];
for (int i = 0; i < ExcelTable.Rows.Count; i++)
if (ExcelTable.Rows[i][0] != null)
{
for (int j = 0; j < ExcelTable.Columns.Count; j++)
{ //将Excel表中的数据存储到数组
data[i, j] = float.Parse(ExcelTable.Rows[i][j].ToString());
}
}
else
{ break; }
}
catch (Exception exception)
{ MessageBox.Show(exception.Message); }
}
引发异常的语句是程序段里的
int iColums = ExcelTable.Columns.Count; 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询