

Parmdpt.Value = xlRange.Cells as .Range).Value2.ToString() Parmname.Value = xlRange.Cells as .Range).Value2.ToString() Parmid.Value = Convert.ToInt32(xlRange.Cells as .Range).Value2.ToString()) What you can do is to loop over the rows only and inside that loop increment the column index statically to read the cells values as below and populate the params: for (int row = 1 row <= rowCount row++)
Sqlpro error while importing table code#
You need to fill those vars with the cells values of excel that you are commenting in the below code: xlRange.Cells as .Range).Value2.ToString()īut as you can see here you are looping over the rows first and for each row you are reading the columns content which will make the above code fail again. You defined the below vars with default values, but it is not populated with the values from Excel, thats why you seeing 0 and empty strings in the DB: int id = 0

SqlCommand cmd = new SqlCommand("SP_Import_Excel", con) Private byte GetImageFromClipboardAsBinary ( ) Throw new Exception("Failed to save row.") ParmImage.Value = GetImageFromClipboardAsBinary() ParmDesignation.Value = Convert.ToString() Var xlWorksheet = xlWorkbook.Sheets as Excel._Worksheet įoreach (Excel.Range row in xlWorksheet.Rows) Var parmDesignation = SqlDbType.NVarChar)

Var cmd = new SqlCommand("SP_Import_Excel", con) Private void InsertPermRecords ( string filePath ) Step through the code with the debugger and ensure it is loops the correct # of times, each time it has the correct values and each time the row is being inserted Without testing, here's the updated code that I can see getting you closer to what you want. Set some variables to the value of fixed column valuesĮxecute the command against the last set of values stored. Set the parameters of the command to the corresponding column value for that row It appears you're simply trying to write the code rather than starting with the algorithm. You need to think about the algorithm of your code. My Excel sheet which I need to import into database: Insert into Import_Excel while executing the above code: XlWorkbook.Close(Type.Missing, Type.Missing, Type.Missing) MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error) MessageBox.Show("Data uploded sucessfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information) XlWorksheet = (Excel._Worksheet)xlWorkbook.Sheets SqlCommand cmd = new SqlCommand(".", con) Ĭmd.CommandType = CommandType.StoredProcedure SqlConnection con = new SqlConnection(scon) Private void InsertPermRecords(string FilePath) If I complete this task my project would be completed please does any one provide me the correct way to achieve this. Here is my code which I used to import excel sheet into database. Since 10 days I'm trying to import excel sheet data's into database along with images,but I couldn't able to achieve it.I tried with all msdn,codepoject & stack overflow examples which are posted earlier even though
