用npoi将excel数据导入到数据库,数据0.9变成了.9怎么办

                 DataTable table = new DataTable();
                OpenFileDialog opfile = new OpenFileDialog();
                opfile.Filter = " xlsx files(*.xls)|*.xls|All files(*.*)|*.*";//选择保存的格式(显示格式|实际格式)
                if (opfile.ShowDialog() == DialogResult.OK)
                {
                    string fileName = opfile.FileName;//获取路径
                    FileStream file = new FileStream(fileName, FileMode.Open, FileAccess.Read);
                   // XSSFWorkbook hssfw = new XSSFWorkbook(file);
                    HSSFWorkbook hssfw = new HSSFWorkbook(file);
                    ISheet sheet = hssfw.GetSheetAt(0);
                    System.Collections.IEnumerator rows = sheet.GetRowEnumerator();

                    IRow headerRow = sheet.GetRow(0);
                    int cellCount = headerRow.LastCellNum;

                    for (int j = 0; j < cellCount; j++)
                    {
                        ICell cell = headerRow.GetCell(j);
                        if (cell == null)
                        {
                            table.Columns.Add("");
                        }
                        else
                        {
                            table.Columns.Add(cell.ToString());
                        }
                    }

                    for (int i = (sheet.FirstRowNum + 1); i <= sheet.LastRowNum; i++)
                    {
                        IRow row = sheet.GetRow(i);
                        DataRow dataRow = table.NewRow();

                        for (int j = row.FirstCellNum; j < cellCount; j++)
                        {
                            if (row.GetCell(j) != null)
                                dataRow[j] = row.GetCell(j).ToString();
                        }

                        table.Rows.Add(dataRow);
                    }

                    dgvShowExcel.DataSource = table;
                    foreach (DataRow dr in table.Rows)
                    {
                        SqlConnection conn = new SqlConnection();
                        conn.ConnectionString = ConfigurationManager.ConnectionStrings["partialConnectString"].ToString();
                        SqlCommand cmd = new SqlCommand("Insert Into MCA(m_name,m_type,m_type1,unit,connectString) values (@m_name,@m_type,@m_type1,@unit,@connectString)", conn);
                        cmd.Parameters.Add("@m_name", SqlDbType.VarChar);
                        cmd.Parameters["@m_name"].Value = dr[0].ToString();
                        cmd.Parameters.Add("@m_type", SqlDbType.VarChar);
                        cmd.Parameters["@m_type"].Value = dr[1].ToString();
                        cmd.Parameters.Add("@m_type1", SqlDbType.VarChar);
                        cmd.Parameters["@m_type1"].Value = dr[2].ToString();
                        cmd.Parameters.Add("@unit", SqlDbType.VarChar);
                        cmd.Parameters["@unit"].Value = dr[3].ToString();
                        cmd.Parameters.Add("@connectString", SqlDbType.VarChar);
                        cmd.Parameters["@connectString"].Value = 0;
                        conn.Open();
                        cmd.ExecuteNonQuery();
                        conn.Close();
                    }
                }
                MessageBox.Show("录入成功");
查看全部
hong34210
hong34210
2015/06/10 10:09
  • 数据
  • npoi
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

2个回复