Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

Logic error using foreach data column and data rows in datatable to insert into sql server

$
0
0
foreach (DataColumn dc in dt.Columns) {
	if (dc.ColumnName.ToString() == "Oracle" || dc.ColumnName.ToString() == "F1") {
	} else {
		foreach (DataRow dr in dt.Rows) {
			insertStatement = insertStatement + "INSERT INTO Allocation (OracleCostCenter, OracleGL, Allocation, FiscalYear, Addedby) VALUES ('"+ dr["Oracle"].ToString().Trim() + "','" + dc.ColumnName.ToString() + "','" + dr[dc.ColumnName.ToString()]+ "'," + DropDownList1.SelectedValue + ",'" + addedby1.Text + "')\n";
			SqlCommand sqlCommand = new SqlCommand(insertStatement, conn);
			sqlCommand.ExecuteNonQuery();
		}
	}
}

first sorry for the indentation of my codes....

next is my question. i try the above code... the total amount of data insert to my sql server is abt 10,000 plus datas... i have try in a counter into the foreach loop, and the counter after the end of the 2 foreach loops is 612... so how come my sql server has 10k plus datas being inserted?? it is supposed to have only 612 datas...




Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>