locked
Inserting excel values into mysql database RRS feed

  • Question

  • User120878812 posted

    if (arrDt[cntArr] == "INT" || arrDt[cntArr] == "TINYINT")
                                    tempInt = Convert.ToInt16(dt.Tables[0].Rows[j][cntb]);
                                    else if (arrDt[cntArr] == "VARCHAR" || arrDt[cntArr] == "TEXT")
                                        tempString = dt.Tables[0].Rows[j][cntb].ToString();
                                    else
                                    {
                                        tempDate = Convert.ToDateTime(dt.Tables[0].Rows[j][cntb]);
                                    }
                                    cntArr++;

                                    if (cntb != dt.Tables[0].Columns.Count - 1)
             
                                    {
                                       // val += "\'" + dt.Tables[0].Rows[j][cntb].ToString() + "\',";
                                        val += "\'" + tempInt + "," + tempString + ","+ tempDate +"\'";   
                                    }
                                    else
                                    {
                                        //val += "\'" + dt.Tables[0].Rows[j][cntb].ToString() + "\',";
                                        val += "\'" + tempInt + ","+ tempString + ","+ tempDate +"\'";
                                    }
                                }
                                catch (Exception) { }
                            }
                        }         
                        val = val.Substring(0, val.Length - 1);
                        strQuery = "INSERT INTO rardata ( " + dbField + ") Values(" + val + ")";
                        myCommand.CommandText = strQuery;
                        myCommand.Parameters.Clear();
                        myCommand.Parameters.AddWithValue("dbField", val.Trim());
                        myCommand.ExecuteNonQuery();

    I use the above code for changing the datatype of excel datatype but problem is that convered value is not assigned to the variable "val".When i concat these converted value in val then it first take by default it takes int and date value andin the second itration of the loop it takes value of string from variable"tempString".And i use simple queries .So what can i do please tell me as early as possible.Please help me

    Tuesday, February 14, 2012 4:48 AM

All replies

  • User-384047847 posted

    If you could format your code a little and recheck your writing we could help you better.

    Tuesday, February 14, 2012 5:22 AM