Execl数据上传到数据库
=============================================================asp.net========================================
num = Convert.ToInt32(ini.IniReadValue("Record", "Num").ToString());
num++;
Random random = new Random();
//保存文件的虚拟路径
string path = "UploadFile/";
//获取选择的文件名
string fileName = FileUpload1.FileName;
///文件名称判断
if (true)
{
}
//获取文件扩展名称
string fileExt = Path.GetExtension(fileName);
//生成新文件名
//string newName ="Mes"+ DateTime.Now.ToString("yyyyMMddHHmmssfff") + random.Next(0, 9999).ToString();
string NewName = "MES" + DateTime.Now.ToString("yyyyMMdd") + num.ToString();
ini.IniWriteValue("Record", "Num", num.ToString());
//获取指定虚机路径的物理路径
string fullPath = HttpContext.Current.Server.MapPath(path);
//上传文件保存路径
string savePath = fullPath + NewName + fileExt;
//保存文件到服务器
FileUpload1.SaveAs(savePath);
==================================================================Winform=================================================
/// <summary>
/// 浏览
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void bn_MConfig_Click(object sender, EventArgs e)
{
this.openFileDialog1.Filter = "所有文件(*.*)|*.*";
if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
{
/*
string PicFileName = this.openFileDialog1.FileName;
this.imgList.Add(PicFileName);
this.imageList1.Images.Add(Image.FromFile(PicFileName));
*/
string FileName = this.openFileDialog1.FileName;
tb_file.Text = FileName;
}
}
/// <summary>
/// 文件上传
/// </summary>
/// <param name="openFileDialog"></param>
/// <param name="FileTypeName"></param>
public static void FileUp(OpenFileDialog openFileDialog, string FileTypeName)
{
try
{
//FileTypeName = "Models";
Random random = new Random();
//保存文件的虚拟路径
string path = "UploadFile//" + FileTypeName + "//";
//获取选择的文件名
string fileName = openFileDialog.FileName;
///文件名称判断
if (true)
{
}
//获取文件扩展名称
string fileExt = Path.GetExtension(fileName);
//生成新文件名
//string newName ="Mes"+ DateTime.Now.ToString("yyyyMMddHHmmssfff") + random.Next(0, 9999).ToString();
string NewName = FileTypeName + DateTime.Now.ToString("yyyyMMddHHmmssfff");
//获取指定虚机路径的物理路径
string fullPath = Path.GetDirectoryName(path);
fullPath = Path.GetFullPath(path);
//上传文件保存路径
string savePath = fullPath + NewName + fileExt;
//DBHelpter.MsgBox(savePath);
//保存文件到本地
File.Copy(fileName, savePath);
///获取execl数据
//返回指定目录中的文件的名称(绝对路径)
string[] files = System.IO.Directory.GetFiles(fullPath);
//获取Test文件夹下所有文件名称
string[] files2 = System.IO.Directory.GetFiles(@fullPath, "*", System.IO.SearchOption.AllDirectories);
////获取指定目录下面指定格式的所有文件
//DirectoryInfo di = new DirectoryInfo(@fullPath.TrimEnd('\\'));
//FileInfo[] files1 = new string[] { "*.xlsx", "*.csv", "*.xls" }.SelectMany(i => di.GetFiles(i, SearchOption.AllDirectories)).Distinct().ToArray();
List<long> MESNO = new List<long>();
List<string> FilePathlist = GetFiles(new DirectoryInfo(fullPath), "*.xlsx,*.xls");
for (int i = 0; i < FilePathlist.Count(); i++)
{
string str = FilePathlist[i].Split('.')[0];
string[] sArray = str.Split(new string[] { FileTypeName }, StringSplitOptions.RemoveEmptyEntries);
long NO = Convert.ToInt64(sArray[2]);
MESNO.Add(NO);
}
long max = 0;
for (int i = 0; i < MESNO.Count(); i++)
{
max = MESNO[0];
if (MESNO[i] > max)
{
max = MESNO[i];
}
}
string LastFileName = fullPath + FileTypeName + max + fileExt;
FileSvr fileSvr = new FileSvr();
///有Office配置文件
//DataTable dt = fileSvr.GetExcelDatatable(LastFileName, "mapTable");
///引用NPIO
string msgstr = "";
DataSet ds = NPIOClass.ExcelToDataSet(LastFileName, msgstr);
string name = "";
for (int i = 0; i < ds.Tables.Count; i++)
{
name += ds.Tables[i].TableName + ",";
int num= InsertDatas(ds.Tables[i]);
if (num>0)
{
MessageBox.Show("上传成功!");
}
else
{
MessageBox.Show("上传失败!");
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Physical_planning_system.UploadClass
{
public class NPIOClass
{
/// <summary>
/// Excel转换成DataTable(.xls)
/// </summary>
/// <param name="filePath">Excel文件路径</param>
/// <returns></returns>
public static DataTable ExcelToDataTable(string filePath)
{
var dt = new DataTable();
using (var file = new FileStream(filePath, FileMode.Open, FileAccess.Read))
{
var hssfworkbook = new XSSFWorkbook(file);
var sheet = hssfworkbook.GetSheetAt(0);
for (var j = 0; j < 5; j++)
{
dt.Columns.Add(Convert.ToChar(((int)'A') + j).ToString());
}
var rows = sheet.GetRowEnumerator();
while (rows.MoveNext())
{
var row = (HSSFRow)rows.Current;
var dr = dt.NewRow();
for (var i = 0; i < row.LastCellNum; i++)
{
var cell = row.GetCell(i);
if (cell == null)
{
dr[i] = null;
}
else
{
switch (cell.CellType)
{
case CellType.Blank:
dr[i] = "[null]";
break;
case CellType.Boolean:
dr[i] = cell.BooleanCellValue;
break;
case CellType.Numeric:
dr[i] = cell.ToString();
break;
case CellType.String:
dr[i] = cell.StringCellValue;
break;
case CellType.Error:
dr[i] = cell.ErrorCellValue;
break;
case CellType.Formula:
try
{
dr[i] = cell.NumericCellValue;
}
catch
{
dr[i] = cell.StringCellValue;
}
break;
default:
dr[i] = "=" + cell.CellFormula;
break;
}
}
}
dt.Rows.Add(dr);
}
}
return dt;
}
/// <summary>
/// Excel转换成DataSet(.xlsx/.xls)
/// </summary>
/// <param name="filePath">Excel文件路径</param>
/// <param name="strMsg"></param>
/// <returns></returns>
public static DataSet ExcelToDataSet(string filePath, string strMsg)
{
strMsg = "";
DataSet ds = new DataSet();
DataTable dt = new DataTable();
string fileType = Path.GetExtension(filePath).ToLower();
string fileName = Path.GetFileName(filePath).ToLower();
try
{
ISheet sheet = null;
int sheetNumber = 0;
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
if (fileType == ".xlsx")
{
// 2007版本
XSSFWorkbook workbook = new XSSFWorkbook(fs);
sheetNumber = workbook.NumberOfSheets;
for (int i = 0; i < sheetNumber; i++)
{
string sheetName = workbook.GetSheetName(i);
sheet = workbook.GetSheet(sheetName);
if (sheet != null)
{
dt = GetSheetDataTable(sheet, strMsg);
if (dt != null)
{
dt.TableName = sheetName.Trim();
ds.Tables.Add(dt);
}
else
{
//MessageBox.Show("Sheet数据获取失败,原因:" + strMsg);
}
}
}
}
else if (fileType == ".xls")
{
// 2003版本
HSSFWorkbook workbook = new HSSFWorkbook(fs);
sheetNumber = workbook.NumberOfSheets;
for (int i = 0; i < sheetNumber; i++)
{
string sheetName = workbook.GetSheetName(i);
sheet = workbook.GetSheet(sheetName);
if (sheet != null)
{
dt = GetSheetDataTable(sheet, strMsg);
if (dt != null)
{
dt.TableName = sheetName.Trim();
ds.Tables.Add(dt);
}
else
{
// MessageBox.Show("Sheet数据获取失败,原因:" + strMsg);
}
}
}
}
return ds;
}
catch (Exception ex)
{
strMsg = ex.Message;
return null;
}
}
/// <summary>
/// 获取sheet表对应的DataTable
/// </summary>
/// <param name="sheet">Excel工作表</param>
/// <param name="strMsg"></param>
/// <returns></returns>
private static DataTable GetSheetDataTable(ISheet sheet, string strMsg)
{
strMsg = "";
DataTable dt = new DataTable();
string sheetName = sheet.SheetName;
int startIndex = 0;// sheet.FirstRowNum;
int lastIndex = sheet.LastRowNum;
//最大列数
int cellCount = 0;
IRow maxRow = sheet.GetRow(0);
for (int i = startIndex; i <= lastIndex; i++)
{
IRow row = sheet.GetRow(i);
if (row != null && cellCount < row.LastCellNum)
{
cellCount = row.LastCellNum;
maxRow = row;
}
}
//列名设置
try
{
for (int i = 0; i < maxRow.LastCellNum; i++)//maxRow.FirstCellNum
{
//dt.Columns.Add(Convert.ToChar(((int)'A') + i).ToString());
dt.Columns.Add(maxRow.Cells[i].ToString());
//DataColumn column = new DataColumn("Column" + (i + 1).ToString());
//dt.Columns.Add(column);
}
}
catch
{
strMsg = "工作表" + sheetName + "中无数据";
return null;
}
//数据填充
for (int i = startIndex + 1; i <= lastIndex; i++)
{
IRow row = sheet.GetRow(i);
DataRow drNew = dt.NewRow();
if (row != null)
{
for (int j = row.FirstCellNum; j < row.LastCellNum; ++j)
{
if (row.GetCell(j) != null)
{
ICell cell = row.GetCell(j);
switch (cell.CellType)
{
case CellType.Blank:
drNew[j] = "";
break;
case CellType.Numeric:
short format = cell.CellStyle.DataFormat;
//对时间格式(2015.12.5、2015/12/5、2015-12-5等)的处理
if (format == 14 || format == 31 || format == 57 || format == 58)
drNew[j] = cell.DateCellValue;
else
drNew[j] = cell.NumericCellValue;
if (cell.CellStyle.DataFormat == 177 || cell.CellStyle.DataFormat == 178 || cell.CellStyle.DataFormat == 188)
drNew[j] = cell.NumericCellValue.ToString("#0.00");
break;
case CellType.String:
drNew[j] = cell.StringCellValue;
break;
case CellType.Formula:
try
{
drNew[j] = cell.NumericCellValue;
if (cell.CellStyle.DataFormat == 177 || cell.CellStyle.DataFormat == 178 || cell.CellStyle.DataFormat == 188)
drNew[j] = cell.NumericCellValue.ToString("#0.00");
}
catch
{
try
{
drNew[j] = cell.StringCellValue;
}
catch { }
}
break;
default:
drNew[j] = cell.StringCellValue;
break;
}
}
}
}
dt.Rows.Add(drNew);
}
return dt;
}
}
}
/// <summary>
/// 获取某种类型文件
/// </summary>
/// <param name="directory"></param>
/// <param name="pattern"></param>
/// <returns></returns>
public static List<string> GetFiles(DirectoryInfo directory, string pattern)
{
List<string> Filelist = new List<string>();
if (directory.Exists || pattern.Trim() != string.Empty)
{
string[] ext = pattern.Split(',');
for (int i = 0; i < ext.Count(); i++)
{
foreach (FileInfo info in directory.GetFiles(ext[i]))
{
if (Filelist.Contains(info.FullName.ToString()))
{
continue;
}
Filelist.Add(info.FullName.ToString());
}
foreach (DirectoryInfo info in directory.GetDirectories())
{
GetFiles(info, pattern);
}
}
}
return Filelist;
}
/// <summary>
/// 把table数据添加到数据库
/// </summary>
/// <param name="dt"></param>
/// <returns></returns>
public static int InsertDatas(DataTable dt)
{
try
{
string tablename = dt.TableName;
if (tablename == "L5标配清单")
{
}
else if (tablename == "BE标配清单")
{
}
else if (tablename == "CFC标配清单")
{
foreach (DataRow dr in dt.Rows)
{
string Process_section = "0"; string classification = "0"; string classes_name = "0"; string name = "0"; string IBIS = "0"; string Houdini = "0"; string Andy_NA = "0";
string Golden_Eagle = "0"; string George_NA = "0"; string Zap = "0"; string Heart = "0"; string STINGRAY = "0"; string Quattro = "0"; string Zippo = "0"; string RIO_H = "0";
string RIO_H_TMO = "0"; string RIO_M = "0"; string George_Row = "0"; string Zach = "0"; string D52_Row = "0"; string D52PRC = "0"; string Andy_Row = "0"; string Dante = "0";
string P3G = "0"; string P4G = "0"; string Teller = "0"; string Blaine = "0"; string K9_note = "0"; string K9_S = "0"; string Robusta_2 = "0"; string Troika = "0"; string Oslo_M_Row = "0";
string DOHA = "0";
string Oslo_M_NA = "0";
string Oslo_M_IMT = "0";
string Oslo_H_Row = "0";
string Oslo_H_NA = "0";
string Rugby = "0";
string Rugby_GO = "0";
string Golf_Lite = "0";
string Surf_NA = "0";
string Ashley_lite = "0";
string Poker = "0";
string JIMNY_ROW = "0";
string JIMNY = "0";
string Ashley_NA = "0";
string Andy_4 = "0";
string Auqa = "0";
string A600X = "0";
string Q6003 = "0";
string Q6005 = "0";
string Q6006 = "0";
string Q6008 = "0";
string A6090 = "0";
string A6095 = "0";
string A6505 = "0";
string A6096 = "0";
string A6093 = "0";
string A6097 = "0";
string A6072 = "0";
string Q6070 = "0";
string Q6071 = "0";
string P3588 = "0";
string P400 = "0";
string P407 = "0";
string M7 = "0";
string V7 = "0";
string M8 = "0";
string SPARROW = "0";
string T400 = "0";
string Rossion = "0";
string Yeti2 = "0";
string ACHILLES_5_PLUS_BUNDLE = "0";
string ACHILLES_5_PLUS = "0";
string Achilles_5_L = "0";
string P2I = "0";
object a;
for (int i = 0; i < dr.ItemArray.Count(); i++)
{
a= dr.ItemArray[i];
}
if (dr["Process section"].ToString()!=string.Empty|| dr["Process section"].ToString()!="")
{
Process_section = dr["Process section"].ToString();
}
if (dr["classification "].ToString() != string.Empty || dr["classification "].ToString() != "")
{
classification = dr["classification "].ToString();
}
if (dr["classes"].ToString() != string.Empty || dr["classes"].ToString() != "")
{
classes_name = dr["classes"].ToString();
}
if (dr["name"].ToString() != string.Empty || dr["name"].ToString() != "")
{
name = dr["name"].ToString();
}
if (dr["IBIS"].ToString() != string.Empty || dr["IBIS"].ToString() != "")
{
IBIS = dr["IBIS"].ToString();
}
if (dr["Houdini"].ToString() != string.Empty || dr["Houdini"].ToString() != "")
{
Houdini = dr["Houdini"].ToString();
}
if (dr["Andy NA"].ToString() != string.Empty || dr["Andy NA"].ToString() != "")
{
Andy_NA = dr["Andy NA"].ToString();
}
if (dr["Golden Eagle"].ToString() != string.Empty || dr["Golden Eagle"].ToString() != "")
{
Golden_Eagle = dr["Golden Eagle"].ToString();
}
if (dr["George NA"].ToString() != string.Empty || dr["George NA"].ToString() != "")
{
George_NA = dr["George NA"].ToString();
}
if (dr["Zap"].ToString() != string.Empty || dr["Zap"].ToString() != "")
{
Zap = dr["Zap"].ToString();
}
if (dr["Heart"].ToString() != string.Empty || dr["Heart"].ToString() != "")
{
Heart = dr["Heart"].ToString();
}
if (dr["STINGRAY"].ToString() != string.Empty || dr["STINGRAY"].ToString() != "")
{
STINGRAY = dr["STINGRAY"].ToString();
}
if (dr["Quattro "].ToString() != string.Empty || dr["Quattro "].ToString() != "")
{
Quattro = dr["Quattro "].ToString();
}
if (dr["Zippo"].ToString() != string.Empty || dr["Zippo"].ToString() != "")
{
Zippo = dr["Zippo"].ToString();
}
if (dr["RIO H"].ToString() != string.Empty || dr["RIO H"].ToString() != "")
{
RIO_H = dr["RIO H"].ToString();
}
if (dr["RIO H TMO"].ToString() != string.Empty || dr["RIO H TMO"].ToString() != "")
{
RIO_H_TMO = dr["RIO H TMO"].ToString();
}
if (dr["RIO M"].ToString() != string.Empty || dr["RIO M"].ToString() != "")
{
RIO_M = dr["RIO M"].ToString();
}
if (dr["George Row"].ToString() != string.Empty || dr["George Row"].ToString() != "")
{
George_Row = dr["George Row"].ToString();
}
if (dr["Zach"].ToString() != string.Empty || dr["Zach"].ToString() != "")
{
Zach = dr["Zach"].ToString();
}
if (dr["D52 Row"].ToString() != string.Empty || dr["D52 Row"].ToString() != "")
{
D52_Row = dr["D52 Row"].ToString();
}
if (dr["D52PRC "].ToString() != string.Empty || dr["D52PRC "].ToString() != "")
{
D52PRC = dr["D52PRC "].ToString();
}
if (dr["Andy Row"].ToString() != string.Empty || dr["Andy Row"].ToString() != "")
{
Andy_Row = dr["Andy Row"].ToString();
}
if (dr["Dante"].ToString() != string.Empty || dr["Dante"].ToString() != "")
{
Dante = dr["Dante"].ToString();
}
if (dr["P3G"].ToString() != string.Empty || dr["P3G"].ToString() != "")
{
P3G = dr["P3G"].ToString();
}
if (dr["P4G"].ToString() != string.Empty || dr["P4G"].ToString() != "")
{
P4G = dr["P4G"].ToString();
}
if (dr["Teller"].ToString() != string.Empty || dr["Teller"].ToString() != "")
{
Teller = dr["Teller"].ToString();
}
if (dr["Blaine"].ToString() != string.Empty || dr["Blaine"].ToString() != "")
{
Blaine = dr["Blaine"].ToString();
}
if (dr["K9 note"].ToString() != string.Empty || dr["K9 note"].ToString() != "")
{
K9_note = dr["K9 note"].ToString();
}
if (dr["K9 S "].ToString() != string.Empty || dr["K9 S "].ToString() != "")
{
K9_S = dr["K9 S "].ToString();
}
if (dr["Robusta 2"].ToString() != string.Empty || dr["Robusta 2"].ToString() != "")
{
Robusta_2 = dr["Robusta 2"].ToString();
}
if (dr["Troika"].ToString() != string.Empty || dr["Troika"].ToString() != "")
{
Troika = dr["Troika"].ToString();
}
if (dr["Oslo M Row"].ToString() != string.Empty || dr["Oslo M Row"].ToString() != "")
{
Oslo_M_Row = dr["Oslo M Row"].ToString();
}
if (dr["DOHA"].ToString() != string.Empty || dr["DOHA"].ToString() != "")
{
DOHA = dr["DOHA"].ToString();
}
if (dr["Oslo M NA"].ToString() != string.Empty || dr["Oslo M NA"].ToString() != "")
{
Oslo_M_NA = dr["Oslo M NA"].ToString();
}
if (dr["Oslo M IMT"].ToString() != string.Empty || dr["Oslo M IMT"].ToString() != "")
{
Oslo_M_IMT = dr["Oslo M IMT"].ToString();
}
if (dr["Oslo H Row"].ToString() != string.Empty || dr["Oslo H Row"].ToString() != "")
{
Oslo_H_Row = dr["Oslo H Row"].ToString();
}
if (dr["Oslo H NA"].ToString() != string.Empty || dr["Oslo H NA"].ToString() != "")
{
Oslo_H_NA = dr["Oslo H NA"].ToString();
}
if (dr["Rugby"].ToString() != string.Empty || dr["Rugby"].ToString() != "")
{
Rugby = dr["Rugby"].ToString();
}
if (dr["Rugby GO"].ToString() != string.Empty || dr["Rugby GO"].ToString() != "")
{
Rugby_GO = dr["Rugby GO"].ToString();
}
if (dr["Golf Lite"].ToString() != string.Empty || dr["Golf Lite"].ToString() != "")
{
Golf_Lite = dr["Golf Lite"].ToString();
}
if (dr["Surf NA"].ToString() != string.Empty || dr["Surf NA"].ToString() != "")
{
Surf_NA = dr["Surf NA"].ToString();
}
if (dr["Ashley lite"].ToString() != string.Empty || dr["Ashley lite"].ToString() != "")
{
Ashley_lite = dr["Ashley lite"].ToString();
}
if (dr["Poker+"].ToString() != string.Empty || dr["Poker+"].ToString() != "")
{
Poker = dr["Poker+"].ToString();
}
if (dr["JIMNY ROW"].ToString() != string.Empty || dr["JIMNY ROW"].ToString() != "")
{
JIMNY_ROW = dr["JIMNY ROW"].ToString();
}
if (dr["JIMNY+"].ToString() != string.Empty || dr["JIMNY+"].ToString() != "")
{
JIMNY = dr["JIMNY+"].ToString();
}
if (dr["Ashley NA"].ToString() != string.Empty || dr["Ashley NA"].ToString() != "")
{ Ashley_NA = dr["Ashley NA"].ToString();
}
if (dr["Andy 4"].ToString() != string.Empty || dr["Andy 4"].ToString() != "")
{
Andy_4 = dr["Andy 4"].ToString();
}
if (dr["Auqa"].ToString() != string.Empty || dr["Auqa"].ToString() != "")
{
Auqa = dr["Auqa"].ToString();
}
if (dr["A600X"].ToString() != string.Empty || dr["A600X"].ToString() != "")
{
A600X = dr["A600X"].ToString();
}
if (dr["Q6003"].ToString() != string.Empty || dr["Q6003"].ToString() != "")
{
Q6003 = dr["Q6003"].ToString();
}
if (dr["Q6005"].ToString() != string.Empty || dr["Q6005"].ToString() != "")
{
Q6005 = dr["Q6005"].ToString();
}
if (dr["Q6006"].ToString() != string.Empty || dr["Q6006"].ToString() != "")
{
Q6006 = dr["Q6006"].ToString();
}
if (dr["Q6008"].ToString() != string.Empty || dr["Q6008"].ToString() != "")
{
Q6008 = dr["Q6008"].ToString();
}
if (dr["A6090"].ToString() != string.Empty || dr["A6090"].ToString() != "")
{
A6090 = dr["A6090"].ToString();
}
if (dr["A6095"].ToString() != string.Empty || dr["A6095"].ToString() != "")
{
A6095 = dr["A6095"].ToString();
}
if (dr["A6505"].ToString() != string.Empty || dr["A6505"].ToString() != "")
{
A6505 = dr["A6505"].ToString();
}
if (dr["A6096"].ToString() != string.Empty || dr["A6096"].ToString() != "")
{
A6096 = dr["A6096"].ToString();
}
if (dr["A6093"].ToString() != string.Empty || dr["A6093"].ToString() != "")
{
A6093 = dr["A6093"].ToString();
}
if (dr["A6097"].ToString() != string.Empty || dr["A6097"].ToString() != "")
{
A6097 = dr["A6097"].ToString();
}
if (dr["A6072"].ToString() != string.Empty || dr["A6072"].ToString() != "")
{
A6072 = dr["A6072"].ToString();
}
if (dr["Q6070"].ToString() != string.Empty || dr["Q6070"].ToString() != "")
{
Q6070 = dr["Q6070"].ToString();
}
if (dr["Q6071"].ToString() != string.Empty || dr["Q6071"].ToString() != "")
{
Q6071 = dr["Q6071"].ToString();
}
if (dr["P3588"].ToString() != string.Empty || dr["P3588"].ToString() != "")
{
P3588 = dr["P3588"].ToString();
}
if (dr["P400"].ToString() != string.Empty || dr["P400"].ToString() != "")
{
P400 = dr["P400"].ToString();
}
if (dr["P407"].ToString() != string.Empty || dr["P407"].ToString() != "")
{
P407 = dr["P407"].ToString();
}
if (dr["M7"].ToString() != string.Empty || dr["M7"].ToString() != "")
{
M7 = dr["M7"].ToString();
}
if (dr["V7"].ToString() != string.Empty || dr["V7"].ToString() != "")
{
V7 = dr["V7"].ToString();
}
if (dr["M8"].ToString() != string.Empty || dr["M8"].ToString() != "")
{
M8 = dr["M8"].ToString();
}
if (dr["SPARROW"].ToString() != string.Empty || dr["SPARROW"].ToString() != "")
{
SPARROW = dr["SPARROW"].ToString();
}
if (dr["T400"].ToString() != string.Empty || dr["T400"].ToString() != "")
{
T400 = dr["T400"].ToString();
}
if (dr["Rossion"].ToString() != string.Empty || dr["Rossion"].ToString() != "")
{
Rossion = dr["Rossion"].ToString();
}
if (dr["Yeti2"].ToString() != string.Empty || dr["Yeti2"].ToString() != "")
{
Yeti2 = dr["Yeti2"].ToString();
}
if (dr["ACHILLES 5 PLUS BUNDLE"].ToString() != string.Empty || dr["ACHILLES 5 PLUS BUNDLE"].ToString() != "")
{
ACHILLES_5_PLUS_BUNDLE = dr["ACHILLES 5 PLUS BUNDLE"].ToString();
}
if (dr["ACHILLES 5 PLUS BUNDLE"].ToString() != string.Empty || dr["ACHILLES 5 PLUS BUNDLE"].ToString() != "")
{
ACHILLES_5_PLUS = dr["ACHILLES 5 PLUS BUNDLE"].ToString();
}
if (dr["Achilles 5 L"].ToString() != string.Empty || dr["Achilles 5 L"].ToString() != "")
{
Achilles_5_L = dr["Achilles 5 L"].ToString();
}
if (dr["P2I"].ToString() != string.Empty || dr["P2I"].ToString() != "")
{
P2I = dr["P2I"].ToString();
}
string insertsql = string.Format("insert into M_config values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}'," +
"'{14}','{15}','{16}','{17}','{18}','{19}','{20}','{21}','{22}','{23}','{24}','{25}','{26}','{27}','{28}','{29}','{30}','{31}','{32}','{33}','{34}'," +
"'{35}','{36}','{37}','{38}','{39}','{40}','{41}','{42}','{43}','{44}','{45}','{46}','{47}','{48}','{49}','{50}','{51}','{52}','{53}','{54}','{55}','{56}','{57}','{58}'," +
"'{59}','{60}','{61}','{62}','{63}','{64}','{65}','{66}','{67}','{68}','{69}','{70}','{71}','{72}','{73}','{74}')", Process_section, classification, classes_name, name, IBIS, Houdini, Andy_NA, Golden_Eagle, George_NA,
Zap, Heart, STINGRAY, Quattro, Zippo, RIO_H, RIO_H_TMO, RIO_M, George_Row, Zach, D52_Row, D52PRC, Andy_Row, Dante, P3G, P4G, Teller,
Blaine, K9_note, K9_S, Robusta_2, Troika, Oslo_M_Row, DOHA, Oslo_M_NA, Oslo_M_IMT, Oslo_H_Row, Oslo_H_NA, Rugby, Rugby_GO, Golf_Lite,
Surf_NA, Ashley_lite, Poker, JIMNY_ROW, JIMNY, Ashley_NA, Andy_4, Auqa, A600X, Q6003, Q6005, Q6006, Q6008, A6090, A6095, A6505, A6096, A6093,
A6097, A6072, Q6070, Q6071, P3588, P400, P407, M7, V7, M8, SPARROW, T400, Rossion, Yeti2, ACHILLES_5_PLUS_BUNDLE, ACHILLES_5_PLUS, Achilles_5_L, P2I
);
int num = DBHlpter.GetNum(insertsql);
}
}
else if (tablename == "BE维修标配清单")
{
}
else if (tablename=="机型开线数量")
{
foreach (DataRow dr in dt.Rows)
{
string model = "";
double OneWeek = 0;
double TwoWeek = 0;
double ThressWeek = 0;
double FourWeek = 0;
double FiveWeek = 0;
double SixWeek = 0;
double ServenWeek = 0;
double EightWeek = 0;
model = dr["机型"].ToString();
OneWeek = Convert.ToDouble(dr["第一周"].ToString());
TwoWeek = Convert.ToDouble(dr["第二周"].ToString());
ThressWeek = Convert.ToDouble(dr["第三周"].ToString());
FourWeek = Convert.ToDouble(dr["第四周"].ToString());
FiveWeek = Convert.ToDouble(dr["第五周"].ToString());
SixWeek = Convert.ToDouble(dr["第六周"].ToString());
ServenWeek = Convert.ToDouble(dr["第七周"].ToString());
EightWeek = Convert.ToDouble(dr["第八周"].ToString());
string insertsqlLine = string.Format("insert into ProductionLine(model,OneProductionLineSum," +
"TwoProductionLineSum,ThreeProductionLineSum," +
"FourProductionLineSum,FiveProductionLineSum,SixProductionLineSum," +
"SenvenProductionLineSum,EightProductionLineSum)values('{0}',{1},{2},{3},{4},{5},{6},{7},{8})", model,OneWeek,TwoWeek,ThressWeek,FourWeek,
FiveWeek,SixWeek,ServenWeek,EightWeek);
int linesum= DBHlpter.GetNum(insertsqlLine);
}
}
else
{
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
return 0;
}
return 1;
}
Execl数据上传到数据库的更多相关文章
- C#工业物联网和集成系统解决方案的技术路线(数据源、数据采集、数据上传与接收、ActiveMQ、Mongodb、WebApi、手机App)
目 录 工业物联网和集成系统解决方案的技术路线... 1 前言... 1 第一章 系统架构... 3 1.1 硬件构架图... 3 1.2 ...
- PDA手持扫描资产标签,盘点完成后将数据上传到PC端,固定资产系统查看盘点结果
固定资产管理系统介绍: 致力于研发条码技术.集成条码系统的专业性公司,针对客户的不同需求,提供一站式的企业条码系统解决方案:包括功能强大的软件系统.安全可靠的无线网络.坚固耐用的硬件系统.灵活易用的管 ...
- C# winform 窗体应用程序之图片上传Oracle数据库保存字段BLOB
C# winform 窗体应用程序之图片上传Oracle数据库保存字段BLOB 我用的数据库是Oracle,就目前来看,许多数据库现在都倾向于Oracle数据库,对ORACLE数据库基本的操作也是必须 ...
- 个人永久性免费-Excel催化剂功能第20波-Excel与Sqlserver零门槛交互-数据上传篇
Excel作为众多数据存储的交换介质,在不同的系统内的数据很少可以很连贯地进行整合分析,一般的业务系统都会提供导出Excel作为标配功能供用户使用系统内生成的数据. 此时最大的问题是,Excel很维去 ...
- 如何优化 FineUI 控件库的性能,减少 80% 的数据上传量!
在开始正文之前,请帮忙为当前排名前 10 唯一的 .Net 开源软件 FineUI 投一票: 投票地址: https://code.csdn.net/2013OSSurvey/gitop/codevo ...
- Octopus系列之数据上传格式要求说明
各个数据列要求 价格列:字符串类型[美元价格] 产品名字:可以支持"/"等字符 分类名字:去空格处理 不得包含"&"符号 主图:一定要有主图列 不为空 ...
- 重新想象 Windows 8.1 Store Apps (89) - 通信的新特性: 下载数据, 上传数据, 上传文件
[源码下载] 重新想象 Windows 8.1 Store Apps (89) - 通信的新特性: 下载数据, 上传数据, 上传文件 作者:webabcd 介绍重新想象 Windows 8.1 Sto ...
- C#数据上传方法
/// <summary> /// 连接成功后开始调用数据上传程序 /// </summary> public void CallDataUpload() { //指定上传日期 ...
- 【AllJoyn专题】基于AllJoyn和Yeelink的传感器数据上传与指令下行的研究
接触高通物联网框架AllJoyn不太久,但确是被深深地吸引了.在我看来,促进我深入学习的原因有三点:一.AllJoyn开源,对开源的软硬件总会有种莫名的喜爱,虽然或许不会都深入下去:二.顺应潮流,物联 ...
随机推荐
- nginx、redis在Centos7中,加入开机自启动
nginx加入开机启动 cat <<EOF >> /etc/systemd/system/nginx.service> [Unit]> Description=ng ...
- zz:NETCONF协议详解
随着SDN的大热,一个诞生了十年之久的协议焕发了第二春,它就是NETCONF协议.如果你在两年前去搜索NETCONF协议,基本得到的信息都是"这个协议是一个网管协议,主要目的是弥补SNMP协 ...
- IOS之文件夹创建、删除,图片在本地的保存和加载
本文转自http://blog.csdn.net/toddmi/article/details/8204102 = (NSCachesDirectory, NSUserDomainMask, YES) ...
- P4072 [SDOI2016](BZOJ4518) 征途 [斜率优化DP]
题目描述 Pine开始了从S地到T地的征途. 从S地到T地的路可以划分成n段,相邻两段路的分界点设有休息站. Pine计划用m天到达T地.除第m天外,每一天晚上Pine都必须在休息站过夜.所以,一段路 ...
- linux google protobuf
说明: protobuf已经全面迁移到github,地址:https://github.com/google/protobuf 直接下载2.6.1版本:https://github.com/googl ...
- 基于iCamera测试500w摄像头-mt9p001,mt9p031,mt9p001模块小结
基于iCamera测试500w摄像头-mt9p001,mt9p031,mt9p001模块小结 先看实物 M12标准无畸变镜头效果 标准CS镜头效果 iCamera底板+mt9p001安装效果 再看看c ...
- 【CSS】352- 有趣的CSS弹跳动画
点击上方"前端自习课"关注,学习起来~ 这是只用了一个div来做的小动画,纯粹利用CSS3的animation来完成,就像是一个正方形在地上弹跳,碰到地面的时候尖角还会压缩变圆,阴 ...
- 【JS】336- 拆解 JavaScript 中的异步模式
点击上方"前端自习课"关注,学习起来~ JavaScript 中有很多种异步编程的方式.callback.promise.generator.async await 甚至 RxJS ...
- C# 导出pdf(浏览器不预览直接下载)
一.接口部分的代码 [HttpGet] public HttpResponseMessage ExportPdf(string id) { string pdfName = ""; ...
- python学习-if
# 判断"""if 条件(True/False): 条件为真时,执行的代码(要干的事情)[elif 条件: 条件为真时,执行的代码(要干的事情)elif 条件: 条件为真 ...