private int rowMax = 0;
dgSplitData.CurrentCell = dgSplitData[0, 0];
string tempStrSQL;
//rowMax为当前DataGridView中最大行号
for (int i = rowMax; rowMax < dgSplitData.Rows.Count; rowMax++)
{
if (this.dgSplitData.Rows[rowMax].Cells[0].Value == null)
{
break;
}
else
{
string cargoCoName = dgSplitData.Rows[rowMax].Cells[0].Value.ToString().Trim();
string splitWeight = dgSplitData.Rows[rowMax].Cells[1].Value.ToString().Trim();
string shipName = dgSplitData.Rows[rowMax].Cells["ShipName"].Value.ToString().Trim();
string column3 = dgSplitData.Rows[rowMax].Cells["Column3"].Value.ToString().Trim();
string remark = dgSplitData.Rows[rowMax].Cells["Remark"].Value.ToString().Trim();
string sendValues = "(‘" + cargoCoName + "‘,‘" + splitWeight + "‘,‘" + shipName + "‘,‘" + column3 + "‘ ,‘" + remark + "‘)";
tempStrSQL = "insert into t_SplitData (CargoCompany,Weight,ShipName,Commodity,Remark) values" + sendValues; App.UpdateDataBase(tempStrSQL);
}
原文:http://www.cnblogs.com/haimingkaifa/p/5478525.html