//Đoạn code duyệt wa từng d•ng v… lưu xuống cơ sở dữ liệu
foreach (DataGridViewRow dataGridViewRow in dgv_DBV.Rows)
//Declare a null DataRow
DataRow dr = null;
try
{
//Declare a DataRowView(DataRowView)
DataRowView dataRowView = (DataRowView)dataGridViewRow.DataBoundItem;
dr=dataRowView.Row;
}
//Catch the exception
catch (Exception ex)
{
//Write the error message
System.Diagnostics.
Debug.WriteLine(“Error: “+ ex.Message);
//If the row is null
if (dr == null)
{
continue;
}
try
{
MessageBox.Show((dr["tongso"].ToString()));
xuly.Maxn =
Convert.ToDouble(dr["maxn"].ToString());
xuly.Quy =
Convert.ToInt16(numeric.Value.ToString());
xuly.Nam =
Convert.ToInt16(txtnam.Text.ToString());
xuly.Tongso =
Convert.ToDouble(dr["tongso"].ToString());
xuly.Trongdonoitru =
Convert.ToDouble(dr["trongdonoitru"].ToString());xuly.SaveData();
}
catch (Exception ex)
{
//Write the error message
System.Diagnostics.
Debug.WriteLine(“Error: “ + ex.Message);
Đăng trong: Tin Tức | Thẻ: duyệt qua từng dòng và lưu CSDL, Tin Tức






















Hix …Trung ku… mày viết cái gì tao chẳng hiểu luôn ..
He he ..^_^
Ok! Đoạn code mà tao viết là để xử dụng trong trường hợp kết nối hai table thành một table chung và chỉ lưu dữ liệu xuống một bảng trong hai bảng đó. một bảng kia thi sẽ giữ cố định. Đoạn code đó nó sẽ duyệt qua từng dòng trong Datagridview và sẽ lưu từng dòng xuống..