DataGridView의 각 행을 반복하는 경우 아래 메서드를 사용하여 특정 행의 지정된 Column 값을 가져올 수 있습니다.
private T GetDataGridViewTextBoxValue<T>(int rowIndex, string columnName)
{
try
{
return (T)Convert.ChangeType(dataGridViewImport.Rows[rowIndex].Cells[columnName].Value, typeof(T));
}
catch (Exception e)
{
throw new InvalidOperationException(String.Format("Row : {0}, column : {1} could not be cast to {2}", rowIndex, columnName, typeof(T)), e);
}
}
그리고 다음과 같은 방법을 사용할 수 있습니다.
for(int i=0;i< ds2.Tables[0].Rows.Count(); i++)
{
var column1 = GetDataGridViewTextBoxValue<string>(i, "column1");
//Get the rest of the row values.
//In your DAL class you must have a Method that updates the row
//and then just pass in the values that you want.
}
DAL.Display_all()에서 무엇을하고 있습니까? 데이터 집합이 DataGridView로 자동 업데이트됩니다. – Wowa
업데이트 된 행을 가져 와서 데이터베이스를 업데이트하는 방법을 묻는 것 같습니까? – Jethro
나는 연결이 열려있는 SQL 쿼리를 가지고 있으며 DAL에서 dataSet을 반환하면 위에서 언급 한 내용을 수행합니다. –