2012-03-05 55 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#中,你需要翻译它。然后将您的对象传递给此方法,并将返回值分配给您的文本框文本属性。

相关问题