2012-03-05 54 views
0

你好我有一個問題,當我點擊進入數據網格我總是得到這個問題我目前正在做這個更新,我使用數據網格視圖使我更容易點擊數據網格,更新按鈕將被啓用,當我點擊更新按鈕時,它將進入form4維護模塊。但不幸的是,錯誤「從類型'DBNull'轉換類型'字符串'是無效的」得到的總是在我的方式,所以我可以到那一部分,請幫助我的謝謝,再次抱歉我的英語不好:))DBNull類型字符串是無效--- Visual Studio 2005

Form4.txtEmpLastname.Text = dgvEmployeeRecords.Item("Lastname", dgvEmployeeRecords.CurrentRow.Index).Value 
     Form4.txtEmpFirstname.Text = dgvEmployeeRecords.Item("Firstname", dgvEmployeeRecords.CurrentRow.Index).Value 
     Form4.txtEmpMiddlename.Text = dgvEmployeeRecords.Item("Middlename", dgvEmployeeRecords.CurrentRow.Index).Value 
     Form4.txtEmpAddress.Text = dgvEmployeeRecords.Item("CityAddress", dgvEmployeeRecords.CurrentRow.Index).Value 
     Form4.txtEmpAge.Text = dgvEmployeeRecords.Item("Age", dgvEmployeeRecords.CurrentRow.Index).Value 
     Form4.txtEmpBirthdate.Text = dgvEmployeeRecords.Item("Birthdate", dgvEmployeeRecords.CurrentRow.Index).Value 
     Form4.txtEmpBirthplace.Text = dgvEmployeeRecords.Item("Birthplace", dgvEmployeeRecords.CurrentRow.Index).Value 

回答

0

你可以通過將你的值傳入下面的方法來處理這些情況。

string HandleDBNull(object ObjectValue) 
{ 
    if(ObjectValue is DBNull) 
    return ""; 
    else 
    return ObjectValue.ToString(); 
} 

這是在C#中,你需要翻譯它。然後將您的對象傳遞給此方法,並將返回值分配給您的文本框文本屬性。

相關問題