Hi All,
Please go thru the below code. I am trying to read data from Excel using Linq to Excel and need to push it to SQL Server. It's a type of Data Migration. Now problem is i am able to load Excel data into var. Now need to forward that into SQLCommand. Now, at for each loop where i am trying to read data into SQL Command it is showing Stack overflow exception.
Kindly help.
string[] sheetName = new string[2];
sheetName[0] = "ccipra-v212r0-f1";
sheetName[1] = "ccipra-v212r0-f2";
var excelFile = new LinqToExcel.ExcelQueryFactory(txtNCCIExcel.Text);
ar ncciData = from a in excelFile.Worksheet<Class.NCCIData>(sheetName[0]) select a;
using (System.Data.SqlClient.SqlConnection NCCIConn = SQLDAL.GetSQLConnection())
{
<big>foreach (var cc in ncciData)
{
System.Data.SqlClient.SqlCommand comm = new System.Data.SqlClient.SqlCommand();
comm.CommandText = "Insert into NCCIData(Column1, Column2, PriorTo1996, EffectiveDate, DeletionDate, Modifier, PTPEditRationale, Leaf, [Version]) " +
"Values(@col1, @col2, @PT1996, @Effect, @Deletion, @Modifier, @PTP, @Leaf, @Ver)";
comm.Parameters.Add(new System.Data.SqlClient.SqlParameter("@col1", cc.Column1.ToString()));
comm.Parameters.Add(new System.Data.SqlClient.SqlParameter("@col2", cc.Column2.ToString()));
comm.Parameters.Add(new System.Data.SqlClient.SqlParameter("@PT1996", cc.PriorTo1996.ToString()));
comm.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Effect", cc.EffectiveDate.ToString()));
comm.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Deletion", cc.DeletionDate.ToString()));
comm.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Modifier", cc.Modifier.ToString()));
comm.Parameters.Add(new System.Data.SqlClient.SqlParameter("@PTP", cc.PTPEditRationale.ToString()));
comm.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Leaf", cc.Leaf.ToString()));
comm.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Ver", cc.Version.ToString()));
comm.ExecuteNonQuery();
}
}
Thanks In advance.
Raam.