Fad Web Postado Outubro 21, 2010 Denunciar Share Postado Outubro 21, 2010 (editado) Ola tudo bem podem me ajudar não consigo resolver um problema tento ler um arquivo excel para incluir no banco de dados mas da erro E abaixo o código O erro que da e o seguinte leitura Seqüência de entrada não estava em um formato incorreto.o banco de dados em excel http://www.fadmarketing.com.br/bancodados.xlsAgradeço a ajuda using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.IO; using System.Data.OleDb; using MySql.Data.MySqlClient; using System.Globalization; public partial class ImportarDados : System.Web.UI.Page { // Variavel do caminho onde foi upado o arquivo private string ArquivoUpado; string caminhoArq = ""; //string enderecoUrl = ""; // String de conexao do banco de dados MYSQL private string _conexaoMySQL = ""; protected void Page_Load(object sender, EventArgs e) { lblMessagem.Text = ""; } protected void btnEnviarArq_Click(object sender, EventArgs e) { UploadArquivo(); } private void UploadArquivo() { if (FileUpload1.HasFile) try { FileUpload1.SaveAs(caminhoArq + FileUpload1.FileName); string arq = FileUpload1.PostedFile.FileName; //verificamos a extensão através dos últimos 4 caracteres string extensao = arq.Substring(arq.Length - 4).ToLower(); lblMessagem.Text = "Nome do arquivo: " + arq + "<br>Tamanho do arquivo:" + FileUpload1.PostedFile.ContentLength + "<br> Tipo de arquivo: " + FileUpload1.PostedFile.ContentType + "<br>Extensao: " + extensao; //Atribuo valor a variavel ArquivoUpado = caminhoArq + FileUpload1.PostedFile.FileName; // LER O ARQUIVO UPADO if (extensao == ".xls") { LerXlsForcado(); } } catch (Exception ex) { lblMessagem.Text = "ERRO CRITICO NO UPLOAD :" + ex.Message.ToString(); } else { lblMessagem.Text = null; } } private void LerXlsForcado() { #region CONFIG LEITURA // Create a NumberFormatInfo object and set several of its // properties that apply to numbers. NumberFormatInfo provider = new NumberFormatInfo(); provider.NumberDecimalSeparator = ","; provider.NumberGroupSeparator = "."; provider.NumberGroupSizes = new int[] { 3 }; //// LER O XLS COM TABELA E CAMPOS DEFINIDOS string _conectionstring; string _caminhohArquivo = ArquivoUpado; //// define a string de conexao com provedor caminho e nome do banco de dados _conectionstring = @"Provider=Microsoft.Jet.OLEDB.4.0;"; _conectionstring += "Data Source=" + _caminhohArquivo + ";"; _conectionstring += "Extended Properties='Excel 8.0;HDR=YES;'"; ////define a instrução SQLstring string strSql = "Select * from [Base de Dados $]"; #endregion FIM DO CONFIG LEITURA try ////LEITURA EXECEL { #region LEITURA DO EXCEL //cria a conexão com o banco de dados OleDbConnection cn = new OleDbConnection(_conectionstring); //cria o objeto command para executar a instruçao sql OleDbCommand cmdOldbXls = new OleDbCommand(strSql, cn); //abre a conexao cn.Open(); //define o tipo do comando cmdOldbXls.CommandType = CommandType.Text; //cria um dataadapter OleDbDataAdapter da = new OleDbDataAdapter(cmdOldbXls); //cria um objeto datatable DataTable dt = new DataTable(); //preenche o datatable via dataadapter da.Fill(dt); //atribui o datatable ao datagridview para exibir o resultado GridView1.DataSource = dt; GridView1.DataBind(); ////QUANDO FOR WEB lblMessagem.Text = "LEU COM SUCESSO"; #endregion FIM DA LEITURA DO EXCEL foreach (DataRow DR in dt.Rows) { #region LEITURA DO DATAREAD DO EXCEL double vr_campo001 = Convert.ToDouble(DR[0].ToString()); string vr_campo002 = DR[1].ToString(); string vr_campo003 = DR[2].ToString(); string vr_campo004 = DR[3].ToString(); string vr_campo005 = DR[4].ToString(); string vr_campo006 = DR[5].ToString(); string vr_campo007 = DR[6].ToString(); string vr_campo008 = DR[7].ToString(); string vr_campo009 = DR[8].ToString(); string vr_campo010 = DR[9].ToString(); string vr_campo011 = DR[10].ToString(); string vr_campo012 = DR[11].ToString(); string vr_campo013 = DR[12].ToString(); string vr_campo014 = DR[13].ToString(); string vr_campo015 = DR[14].ToString(); string vr_campo016 = DR[15].ToString(); string vr_campo017 = DR[16].ToString(); string vr_campo018 = DR[19].ToString(); // ATE AQUI E STRING double vr_campo019 = Convert.ToDouble(DR[20].ToString()); double vr_campo020 = Convert.ToDouble(DR[21].ToString()); double vr_campo021 = Convert.ToDouble(DR[22].ToString()); double vr_campo022 = Convert.ToDouble(DR[23].ToString()); double vr_campo023 = Convert.ToDouble(DR[24].ToString()); double vr_campo024 = Convert.ToDouble(DR[25].ToString()); double vr_campo025 = Convert.ToDouble(DR[26].ToString()); double vr_campo026 = Convert.ToDouble(DR[27].ToString()); double vr_campo027 = Convert.ToDouble(DR[28].ToString()); double vr_campo028 = Convert.ToDouble(DR[29].ToString()); double vr_campo029 = Convert.ToDouble(DR[30].ToString()); double vr_campo030 = Convert.ToDouble(DR[31].ToString()); double vr_campo031 = Convert.ToDouble(DR[32].ToString()); double vr_campo032 = Convert.ToDouble(DR[33].ToString()); double vr_campo033 = Convert.ToDouble(DR[34].ToString()); double vr_campo034 = Convert.ToDouble(DR[35].ToString()); double vr_campo035 = Convert.ToDouble(DR[36].ToString()); double vr_campo036 = Convert.ToDouble(DR[37].ToString()); double vr_campo037 = Convert.ToDouble(DR[38].ToString()); double vr_campo038 = Convert.ToDouble(DR[39].ToString()); double vr_campo039 = Convert.ToDouble(DR[40].ToString()); double vr_campo040 = Convert.ToDouble(DR[41].ToString()); double vr_campo041 = Convert.ToDouble(DR[42].ToString()); double vr_campo042 = Convert.ToDouble(DR[43].ToString()); double vr_campo043 = Convert.ToDouble(DR[44].ToString()); double vr_campo044 = Convert.ToDouble(DR[45].ToString()); double vr_campo045 = Convert.ToDouble(DR[46].ToString()); double vr_campo046 = Convert.ToDouble(DR[47].ToString()); double vr_campo047 = Convert.ToDouble(DR[48].ToString()); double vr_campo048 = Convert.ToDouble(DR[49].ToString()); double vr_campo049 = Convert.ToDouble(DR[50].ToString()); double vr_campo050 = Convert.ToDouble(DR[51].ToString()); double vr_campo051 = Convert.ToDouble(DR[52].ToString()); double vr_campo052 = Convert.ToDouble(DR[53].ToString()); double vr_campo053 = Convert.ToDouble(DR[54].ToString()); double vr_campo054 = Convert.ToDouble(DR[55].ToString()); double vr_campo055 = Convert.ToDouble(DR[56].ToString()); double vr_campo056 = Convert.ToDouble(DR[57].ToString()); double vr_campo057 = Convert.ToDouble(DR[58].ToString()); double vr_campo058 = Convert.ToDouble(DR[59].ToString()); double vr_campo059 = Convert.ToDouble(DR[60].ToString()); double vr_campo060 = Convert.ToDouble(DR[61].ToString()); double vr_campo061 = Convert.ToDouble(DR[62].ToString()); double vr_campo062 = Convert.ToDouble(DR[63].ToString()); double vr_campo063 = Convert.ToDouble(DR[64].ToString()); double vr_campo064 = Convert.ToDouble(DR[65].ToString()); double vr_campo065 = Convert.ToDouble(DR[66].ToString()); double vr_campo066 = Convert.ToDouble(DR[67].ToString()); double vr_campo067 = Convert.ToDouble(DR[68].ToString()); double vr_campo068 = Convert.ToDouble(DR[69].ToString()); double vr_campo069 = Convert.ToDouble(DR[70].ToString()); double vr_campo070 = Convert.ToDouble(DR[71].ToString()); double vr_campo071 = Convert.ToDouble(DR[72].ToString()); double vr_campo072 = Convert.ToDouble(DR[73].ToString()); double vr_campo073 = Convert.ToDouble(DR[74].ToString()); double vr_campo074 = Convert.ToDouble(DR[75].ToString()); double vr_campo075 = Convert.ToDouble(DR[76].ToString()); double vr_campo076 = Convert.ToDouble(DR[77].ToString()); double vr_campo077 = Convert.ToDouble(DR[78].ToString()); double vr_campo078 = Convert.ToDouble(DR[79].ToString()); double vr_campo079 = Convert.ToDouble(DR[80].ToString()); double vr_campo080 = Convert.ToDouble(DR[81].ToString()); double vr_campo081 = Convert.ToDouble(DR[82].ToString()); double vr_campo082 = Convert.ToDouble(DR[83].ToString()); double vr_campo083 = Convert.ToDouble(DR[84].ToString()); double vr_campo084 = Convert.ToDouble(DR[85].ToString()); double vr_campo085 = Convert.ToDouble(DR[86].ToString()); double vr_campo086 = Convert.ToDouble(DR[87].ToString()); double vr_campo087 = Convert.ToDouble(DR[88].ToString()); double vr_campo088 = Convert.ToDouble(DR[89].ToString()); double vr_campo089 = Convert.ToDouble(DR[90].ToString()); double vr_campo090 = Convert.ToDouble(DR[91].ToString()); double vr_campo091 = Convert.ToDouble(DR[92].ToString()); double vr_campo092 = Convert.ToDouble(DR[93].ToString()); double vr_campo093 = Convert.ToDouble(DR[94].ToString()); double vr_campo094 = Convert.ToDouble(DR[95].ToString()); double vr_campo095 = Convert.ToDouble(DR[96].ToString()); double vr_campo096 = Convert.ToDouble(DR[97].ToString()); double vr_campo097 = Convert.ToDouble(DR[98].ToString()); double vr_campo098 = Convert.ToDouble(DR[99].ToString()); double vr_campo099 = Convert.ToDouble(DR[100].ToString()); double vr_campo100 = Convert.ToDouble(DR[101].ToString()); double vr_campo101 = Convert.ToDouble(DR[102].ToString()); double vr_campo102 = Convert.ToDouble(DR[103].ToString()); double vr_campo103 = Convert.ToDouble(DR[104].ToString()); double vr_campo104 = Convert.ToDouble(DR[105].ToString()); double vr_campo105 = Convert.ToDouble(DR[106].ToString()); double vr_campo106 = Convert.ToDouble(DR[107].ToString()); double vr_campo107 = Convert.ToDouble(DR[108].ToString()); double vr_campo108 = Convert.ToDouble(DR[109].ToString()); double vr_campo109 = Convert.ToDouble(DR[110].ToString()); double vr_campo110 = Convert.ToDouble(DR[111].ToString()); double vr_campo111 = Convert.ToDouble(DR[112].ToString()); double vr_campo112 = Convert.ToDouble(DR[113].ToString()); double vr_campo113 = Convert.ToDouble(DR[114].ToString()); double vr_campo114 = Convert.ToDouble(DR[115].ToString()); double vr_campo115 = Convert.ToDouble(DR[116].ToString()); double vr_campo116 = Convert.ToDouble(DR[117].ToString()); double vr_campo117 = Convert.ToDouble(DR[118].ToString()); double vr_campo118 = Convert.ToDouble(DR[119].ToString()); double vr_campo119 = Convert.ToDouble(DR[120].ToString()); double vr_campo120 = Convert.ToDouble(DR[121].ToString()); double vr_campo121 = Convert.ToDouble(DR[122].ToString()); double vr_campo122 = Convert.ToDouble(DR[123].ToString()); double vr_campo123 = Convert.ToDouble(DR[124].ToString()); double vr_campo124 = Convert.ToDouble(DR[125].ToString()); double vr_campo125 = Convert.ToDouble(DR[126].ToString()); double vr_campo126 = Convert.ToDouble(DR[127].ToString()); double vr_campo127 = Convert.ToDouble(DR[128].ToString()); double vr_campo128 = Convert.ToDouble(DR[129].ToString()); double vr_campo129 = Convert.ToDouble(DR[130].ToString()); double vr_campo130 = Convert.ToDouble(DR[131].ToString()); double vr_campo131 = Convert.ToDouble(DR[132].ToString()); double vr_campo132 = Convert.ToDouble(DR[133].ToString()); double vr_campo133 = Convert.ToDouble(DR[134].ToString()); double vr_campo134 = Convert.ToDouble(DR[135].ToString()); double vr_campo135 = Convert.ToDouble(DR[136].ToString()); double vr_campo136 = Convert.ToDouble(DR[137].ToString()); double vr_campo137 = Convert.ToDouble(DR[138].ToString()); double vr_campo138 = Convert.ToDouble(DR[139].ToString()); double vr_campo139 = Convert.ToDouble(DR[140].ToString()); double vr_campo140 = Convert.ToDouble(DR[141].ToString()); double vr_campo141 = Convert.ToDouble(DR[142].ToString()); double vr_campo142 = Convert.ToDouble(DR[143].ToString()); double vr_campo143 = Convert.ToDouble(DR[144].ToString()); double vr_campo144 = Convert.ToDouble(DR[145].ToString()); double vr_campo145 = Convert.ToDouble(DR[146].ToString()); double vr_campo146 = Convert.ToDouble(DR[147].ToString()); double vr_campo147 = Convert.ToDouble(DR[148].ToString()); double vr_campo148 = Convert.ToDouble(DR[149].ToString()); double vr_campo149 = Convert.ToDouble(DR[150].ToString()); double vr_campo150 = Convert.ToDouble(DR[151].ToString()); double vr_campo151 = Convert.ToDouble(DR[152].ToString()); double vr_campo152 = Convert.ToDouble(DR[153].ToString()); double vr_campo153 = Convert.ToDouble(DR[154].ToString()); double vr_campo154 = Convert.ToDouble(DR[155].ToString()); double vr_campo155 = Convert.ToDouble(DR[156].ToString()); double vr_campo156 = Convert.ToDouble(DR[157].ToString()); double vr_campo157 = Convert.ToDouble(DR[158].ToString()); double vr_campo158 = Convert.ToDouble(DR[159].ToString()); double vr_campo159 = Convert.ToDouble(DR[160].ToString()); double vr_campo160 = Convert.ToDouble(DR[161].ToString()); double vr_campo161 = Convert.ToDouble(DR[162].ToString()); double vr_campo162 = Convert.ToDouble(DR[163].ToString()); double vr_campo163 = Convert.ToDouble(DR[164].ToString()); double vr_campo164 = Convert.ToDouble(DR[165].ToString()); double vr_campo165 = Convert.ToDouble(DR[166].ToString()); double vr_campo166 = Convert.ToDouble(DR[167].ToString()); double vr_campo167 = Convert.ToDouble(DR[168].ToString()); double vr_campo168 = Convert.ToDouble(DR[169].ToString()); // INVERTIDO ORDEM // RW double vr_campo174 = Convert.ToDouble(DR[170].ToString()); double vr_campo175 = Convert.ToDouble(DR[171].ToString()); double vr_campo176 = Convert.ToDouble(DR[172].ToString()); double vr_campo177 = Convert.ToDouble(DR[173].ToString()); double vr_campo178 = Convert.ToDouble(DR[174].ToString()); // N0 double vr_campo169 = Convert.ToDouble(DR[175].ToString()); double vr_campo170 = Convert.ToDouble(DR[176].ToString()); double vr_campo171 = Convert.ToDouble(DR[177].ToString()); double vr_campo172 = Convert.ToDouble(DR[178].ToString()); double vr_campo173 = Convert.ToDouble(DR[179].ToString()); // FIM DA ORDEM INVERTIDA double vr_campo179 = double.Parse(DR[180].ToString().Replace(",", ".")); double vr_campo180 = double.Parse(DR[181].ToString().Replace(",", ".")); double vr_campo181 = double.Parse(DR[182].ToString().Replace(",", ".")); double vr_campo182 = double.Parse(DR[183].ToString().Replace(",", ".")); double vr_campo183 = double.Parse(DR[188].ToString().Replace(",", ".")); double vr_campo184 = double.Parse(DR[185].ToString().Replace(",", ".")); double vr_campo185 = double.Parse(DR[186].ToString().Replace(",", ".")); double vr_campo186 = double.Parse(DR[187].ToString().Replace(",", ".")); double vr_campo187 = double.Parse(DR[188].ToString().Replace(",", ".")); double vr_campo188 = double.Parse(DR[189].ToString().Replace(",", ".")); double vr_campo189 = double.Parse(DR[190].ToString().Replace(",", ".")); #endregion FIM DA LEITURA DO DATAREAD try //// MOTAGEM DO SQL { #region MONTAGEM DO SQL TRY String sql = "INSERT INTO TabelaDadosAluno(NumerodeMatricula, Senha, NomeCompleto, ResponsavelFinanceiro, DatadeNascimento, " // 5 [4] + "Endereco, Cidade, CEP, Telefone, Celular1, Celular2, E_mail, E_maildoResponsavel, Book, Turma, Sala, Professor, Observacoes"//13 - [19] + "PR1, EE1, NE1, FL1, PR2, EE2, NE2, FL2, PR3, EE3, NE3, FL3, PR4, EE4, NE4, FL4, PR5, EE5, NE5, FL5, PR6, EE6," //22 ok [41] + "NE6, FL6, PR7, EE7, NE7, FL7, PR8, EE8, NE8, FL8, PR9, EE9, NE9, FL9, PR10, EE10, NE10, FL10," //18- ok [59] + "PR11, EE11, NE11, FL11, PR12, EE12, NE12, FL12, PR13, EE13, NE13, FL13, PR14, EE14, NE14, FL14,"//16- ok [75] + "PR15, EE15, NE15, FL15, PR16, EE16, NE16, FL16, PR17, EE17, NE17, FL17, PR18, EE18, NE18, FL18,"//16 ok -[91] + "PR19, EE19, NE19, FL19, PR20, EE20, NE20, FL20, PR21, EE21, NE21, FL21, PR22, EE22, NE22, FL22,"//16- ok [107] + "PR23, EE23, NE23, FL23, PR24, EE24, NE24, FL24, PR25, EE25, NE25, FL25, PR26, EE26, NE26, FL26,"//16- ok[123] + "PR27, EE27, NE27, FL27, PR28, EE28, NE28, FL28, PR29, EE29, NE29, FL29, PR30, EE30, NE30, FL30,"//16- ok [139] + "NA1, NA2, NA3, NA4, NA5, NA6, NA7, NA8, NA9, NA10, NA11, NA12, NA13, NA14, NA15, NA16,NA17, NA18,"//18- ok [157] + "NA19, NA20, NA21, NA22, NA23, NA24, NA25, NA26, NA27, NA28, NA29, NA30, NO1, NO2, NO3, NO4, NO5,"//17 - ok [169] - 175 -179 + "RW1, RW2, RW3, RW4, RW5,TNO1, TNO2, TNO3, MP1, MP2, MP3, MP4, MF, TMP1, TMP2, TMF)" //16- ok 170-174 - 180 [190] + " VALUES (" // 5+13+22 = 40 + 17 = 57 / 18*2= 36 / 16*6= 96 === 189 + " " + vr_campo001 + " ," + " '" + vr_campo002 + "' ," + " '" + vr_campo003 + "' ," + " '" + vr_campo004 + "' ," + " '" + vr_campo005 + "' ," + " '" + vr_campo006 + "' ," + " '" + vr_campo007 + "' ," + " '" + vr_campo008 + "' ," + " '" + vr_campo009 + "' ," + " '" + vr_campo010 + "' ," + " '" + vr_campo011 + "' ," + " '" + vr_campo012 + "' ," + " '" + vr_campo013 + "' ," + " '" + vr_campo014 + "' ," + " '" + vr_campo015 + "' ," + " '" + vr_campo016 + "' ," + " '" + vr_campo017 + "' ," + " '" + vr_campo018 + "'," + vr_campo019 + " ," + vr_campo020 + " ," + vr_campo021 + " ," + vr_campo022 + " ," + vr_campo023 + " ," + vr_campo024 + " ," + vr_campo025 + " ," + vr_campo026 + " ," + vr_campo027 + " ," + vr_campo028 + " ," + vr_campo029 + " ," + vr_campo030 + " ," + vr_campo031 + " ," + vr_campo032 + " ," + vr_campo033 + " ," + vr_campo034 + " ," + vr_campo035 + " ," + vr_campo036 + " ," + vr_campo037 + " ," + vr_campo038 + " ," + vr_campo039 + " ," + vr_campo040 + " ," + vr_campo041 + " ," + vr_campo042 + " ," + vr_campo043 + " ," + vr_campo044 + " ," + vr_campo045 + " ," + vr_campo046 + " ," + vr_campo047 + " ," + vr_campo048 + " ," + vr_campo049 + " ," + vr_campo050 + " ," + vr_campo051 + " ," + vr_campo052 + " ," + vr_campo053 + " ," + vr_campo054 + " ," + vr_campo055 + " ," + vr_campo056 + " ," + vr_campo057 + " ," + vr_campo058 + " ," + vr_campo059 + " ," + vr_campo060 + " ," + vr_campo061 + " ," + vr_campo062 + " ," + vr_campo063 + " ," + vr_campo064 + " ," + vr_campo065 + " ," + vr_campo066 + " ," + vr_campo067 + " ," + vr_campo068 + " ," + vr_campo069 + " ," + vr_campo070 + " ," + vr_campo071 + " ," + vr_campo072 + " ," + vr_campo073 + " ," + vr_campo074 + " ," + vr_campo075 + " ," + vr_campo076 + " ," + vr_campo077 + " ," + vr_campo078 + " ," + vr_campo079 + " ," + vr_campo080 + " ," + vr_campo081 + " ," + vr_campo082 + " ," + vr_campo083 + " ," + vr_campo084 + " ," + vr_campo085 + " ," + vr_campo086 + " ," + vr_campo087 + " ," + vr_campo088 + " ," + vr_campo089 + " ," + vr_campo090 + " ," + vr_campo091 + " ," + vr_campo092 + " ," + vr_campo093 + " ," + vr_campo094 + " ," + vr_campo095 + " ," + vr_campo096 + " ," + vr_campo097 + " ," + vr_campo098 + " ," + vr_campo099 + " ," + vr_campo100 + " ," + vr_campo101 + " ," + vr_campo102 + " ," + vr_campo103 + " ," + vr_campo104 + " ," + vr_campo105 + " ," + vr_campo106 + " ," + vr_campo107 + " ," + vr_campo108 + " ," + vr_campo109 + " ," + vr_campo110 + " ," + vr_campo111 + " ," + vr_campo112 + " ," + vr_campo113 + " ," + vr_campo114 + " ," + vr_campo115 + " ," + vr_campo116 + " ," + vr_campo117 + " ," + vr_campo118 + " ," + vr_campo119 + " ," + vr_campo120 + " ," + vr_campo121 + " ," + vr_campo122 + " ," + vr_campo123 + " ," + vr_campo124 + " ," + vr_campo125 + " ," + vr_campo126 + " ," + vr_campo127 + " ," + vr_campo128 + " ," + vr_campo129 + " ," + vr_campo130 + " ," + vr_campo131 + " ," + vr_campo132 + " ," + vr_campo133 + " ," + vr_campo134 + " ," + vr_campo135 + " ," + vr_campo136 + " ," + vr_campo137 + " ," + vr_campo138 + " ," + vr_campo139 + " ," + vr_campo140 + " ," + vr_campo141 + " ," + vr_campo142 + " ," + vr_campo143 + " ," + vr_campo144 + " ," + vr_campo145 + " ," + vr_campo146 + " ," + vr_campo147 + " ," + vr_campo148 + " ," + vr_campo149 + " ," + vr_campo150 + " ," + vr_campo151 + " ," + vr_campo152 + " ," + vr_campo153 + " ," + vr_campo154 + " ," + vr_campo155 + " ," + vr_campo156 + " ," + vr_campo157 + " ," + vr_campo158 + " ," + vr_campo159 + " ," + vr_campo160 + " ," + vr_campo161 + " ," + vr_campo162 + " ," + vr_campo163 + " ," + vr_campo164 + " ," + vr_campo165 + " ," + vr_campo166 + " ," + vr_campo167 + " ," + vr_campo168 + " ," + vr_campo169 + " ," + vr_campo170 + " ," + vr_campo171 + " ," + vr_campo172 + " ," + vr_campo173 + " ," + vr_campo174 + " ," + vr_campo175 + " ," + vr_campo176 + " ," + vr_campo177 + " ," + vr_campo178 + " ," + vr_campo179 + " ," + vr_campo180 + " ," + vr_campo181 + " ," + vr_campo182 + " ," + vr_campo183 + " ," + vr_campo184 + " ," + vr_campo185 + " ," + vr_campo186 + " ," + vr_campo187 + " ," + vr_campo188 + " ," + vr_campo189 + ")"; #endregion Fim MONTAGEM DO SQL Response.Write("<br>" + sql + "<br>"); #region INCLUSAO NO BANCO DE DADOS MySqlConnection conMySql = new MySqlConnection(_conexaoMySQL); MySqlCommand cmdMySql = new MySqlCommand(sql, conMySql); conMySql.Open(); cmdMySql.ExecuteNonQuery(); lblMessagem.Text = "SUCESSO AO GRAVAR NO BD "; conMySql.Close(); #endregion } //// MOTAGEM DO SQL catch (Exception ex) //// MOTAGEM DO SQL { lblMessagem.Text = "ERRO CRITICO AO GRAVAR NO BD :" + ex.Message.ToString(); } } ////FIM FOREACH cn.Close(); cn.Dispose(); cmdOldbXls.Dispose(); } ////LEITURA EXECEL catch (Exception ex) ////LEITURA EXECEL { lblMessagem.Text = "Erro leitura " + ex.Message.ToString(); // LblError.Visible = true; } } #region DESATIVADA CSV private void LerArquivoCsvTxt() { //try //{ // ///Para tipo de arquivo CSV ou TXt separado po virgula // StreamReader stream = new StreamReader(ArquivoUpado); // string linha = null; // while ((linha = stream.ReadLine()) != null) // { // string[] linhaSeparada = linha.Split(','); // // vr_nome = linhaSeparada[1]; // //// vr_fone = linhaSeparada[2]; // // Grava no banco de dados os registro lidos do arquivo // //IncluirRegUp(); // Response.Write(linhaSeparada[0] + " " + linhaSeparada[1] + " " + linhaSeparada[2] + "<br>"); // } // stream.Close(); //} //catch (Exception ex) //{ // lblMessagem.Text = "ERRO CRITICO AO LER CSV :" + ex.Message.ToString(); //} } public void IncluirRegUp() { //String sql = // "INSERT INTO TabelaDadosAluno(NumerodeMatricula, NomeCompleto, ResponsavelFinanceiro, DatadeNascimento, " //4 // + "Endereco, Cidade, CEP, Telefone, Celular1, Celular2, E_mail, FL4, PR5, EE5, NE5, FL5, PR6, EE6," //14 // + "NE6, FL6, PR7, EE7, NE7, FL7, PR8, EE8, NE8, FL8, PR9, EE9, NE9, FL9, PR10, EE10, NE10, FL10," //18 // + "PR11, EE11, NE11, FL11, PR12, EE12, NE12, FL12, PR13, EE13, NE13, FL13, PR14, EE14, NE14, FL14,"//16 // + "PR15, EE15, NE15, FL15, PR16, EE16, NE16, FL16, PR17, EE17, NE17, FL17, PR18, EE18, NE18, FL18,"//16 // + "PR19, EE19, NE19, FL19, PR20, EE20, NE20, FL20, PR21, EE21, NE21, FL21, PR22, EE22, NE22, FL22,"//16 // + "PR23, EE23, NE23, FL23, PR24, EE24, NE24, FL24, PR25, EE25, NE25, FL25, PR26, EE26, NE26, FL26,"//16 // + "PR27, EE27, NE27, FL27, PR28, EE28, NE28, FL28, PR29, EE29, NE29, FL29, PR30, EE30, NE30, FL30,"//16 // + "NA1, NA2, NA3, NA4, NA5, NA6, NA7, NA8, NA9, NA10, NA11, NA12, NA13, NA14, NA15, NA16,NA17, NA18,"//18 // + "NA19, NA20, NA21, NA22, NA23, NA24, NA25, NA26, NA27, NA28, NA29, NA30, NO1, NO2, NO3, NO4, NO5,"//17 // + "RW1, RW2, RW3, RW4, RW5,TNO1, TNO2, TNO3, MP1, MP2, MP3, MP4, MF, TMP1, TMP2, TMF)" //16 // + " VALUES ("//167 // // +"'" + vr_nome + "','" + vr_fone // + "')"; //try //{ // MySqlConnection con = new MySqlConnection(_conexaoMySQL); // MySqlCommand cmd = new MySqlCommand(sql, con); // con.Open(); // cmd.ExecuteNonQuery(); // lblMessagem.Text = "SUCESSO AO GRAVAR NO BD "; // con.Close(); //} //catch (Exception ex) //{ // lblMessagem.Text = "ERRO CRITICO AO GRAVAR NO BD :" + ex.Message.ToString(); //} } static string formatter = "{0,-22}{1,-20}{2}"; #endregion // Get the exception type name; remove the namespace prefix. static string GetExceptionType(Exception ex) { string exceptionType = ex.GetType().ToString(); return exceptionType.Substring( exceptionType.LastIndexOf('.') + 1); } static void ConvertToDouble(string numericStr, IFormatProvider provider) { object defaultValue; object providerValue; // Convert numericStr to double without a format provider. try { defaultValue = Convert.ToDouble(numericStr); } catch (Exception ex) { defaultValue = GetExceptionType(ex); } // Convert numericStr to double with a format provider. try { providerValue = Convert.ToDouble(numericStr, provider); } catch (Exception ex) { providerValue = GetExceptionType(ex); } //Console.WriteLine(formatter, numericStr, defaultValue, providerValue); /// return double.Parse(providerValue); } } Editado Outubro 23, 2010 por quintelab Adicionado BBCode Code Citar Link para o comentário Compartilhar em outros sites More sharing options...
0 quintelab Postado Outubro 23, 2010 Denunciar Share Postado Outubro 23, 2010 Tem muito código ae jovem, nos ajude a te ajudar.Filtre melhor a dúvida, em qual linha esta dando o erro?Abraços... Citar Link para o comentário Compartilhar em outros sites More sharing options...
Pergunta
Fad Web
Ola tudo bem podem me ajudar não consigo resolver um problema tento ler um arquivo excel para incluir no banco de dados mas da erro
E abaixo o código
O erro que da e o seguinte leitura Seqüência de entrada não estava em um formato incorreto.
o banco de dados em excel
http://www.fadmarketing.com.br/bancodados.xls
Agradeço a ajuda
Editado por quintelabAdicionado BBCode Code
Link para o comentário
Compartilhar em outros sites
1 resposta a esta questão
Posts Recomendados
Participe da discussão
Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.