DBNull to type String is not valid
DBNull to type String is not valid
DBNull to type String is not valid
DBNull to type String is not valid
DBNull to type String is not valid
DBNull to type String is not valid DBNull to type String is not valid DBNull to type String is not valid DBNull to type String is not valid DBNull to type String is not valid DBNull to type String is not valid DBNull to type String is not valid DBNull to type String is not valid
DBNull to type String is not valid DBNull to type String is not valid
DBNull to type String is not valid
Go Back  Xtreme Visual Basic Talk > > > DBNull to type String is not valid


Reply
 
Thread Tools Display Modes
  #1  
Old 03-05-2012, 11:21 AM
SkrillexBomi SkrillexBomi is offline
Newcomer
 
Join Date: Mar 2012
Posts: 1
Default DBNull to type String is not valid


Hello I have this problem that when the textbox don't have a value I always get this error "Conversion from type 'DBNull' to type 'String' is not valid."

this is my code when you cell click into the data grid the update button will enabled and will go to the form4 where the maintenance module is place. But unfortunately I don't know how to fix the error anyone would like to help me ) oh and sorry for my bad english

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
Form5.txtEmpElem.Text = dgvEmployeeRecords.Item("ElemSchoolName", dgvEmployeeRecords.CurrentRow.Index).Value
Reply With Quote
  #2  
Old 03-05-2012, 11:42 AM
passel's Avatar
passelDBNull to type String is not valid passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

Since this seems to be DB related, I've moved it from the General Forum to the DB forum.

I'm not a DB person, but perhaps if you added .ToString on the end of each line.
If the Value has a Value, i.e. a string, then the String.ToString shouldn't hurt anything,
But if the DB field does not have a Value, then the DBNull.ToString should return an empty string, thus be a valid assignment to a string and hopefully, just clear the Text.

I don't know if that will do it, but it seems likely.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.

Last edited by passel; 03-05-2012 at 11:55 AM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
DBNull to type String is not valid
DBNull to type String is not valid
DBNull to type String is not valid DBNull to type String is not valid
DBNull to type String is not valid
DBNull to type String is not valid
DBNull to type String is not valid DBNull to type String is not valid DBNull to type String is not valid DBNull to type String is not valid DBNull to type String is not valid DBNull to type String is not valid DBNull to type String is not valid
DBNull to type String is not valid
DBNull to type String is not valid
 
DBNull to type String is not valid
DBNull to type String is not valid
 
-->