16,020,459 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Visual Basic questions
View Javascript questions
View .NET questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by wsm.akh@gmail.com (Top 1 by date)
wsm.akh@gmail.com
6-Jan-18 13:23pm
View
I am getting error message "Conversion from type 'DBNull' to type 'String' is not valid." each time while navigating the records whenever any any field comes.
My code is;
Imports System
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Dim CurrentRow As Integer
Dim DST As New DataSet
Dim ds As New DataSet
Dim dv As DataView
Dim cm As CurrencyManager
Dim dataadapter As OleDb.OleDbDataAdapter
Public CON As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Dot Net Projects\vb dot project complete example\DataMovement\DataMovement.accdb")
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
dataadapter = New OleDb.OleDbDataAdapter("SELECT * FROM Table1", CON)
filldatasetandview()
FormLoadKaro()
End Sub
Private Sub FormLoadKaro()
Try
CurrentRow = 0
CON.Open()
dataadapter = New OleDb.OleDbDataAdapter("SELECT * FROM Table1", CON)
dataadapter.Fill(DST, "Table1")
ShowData(CurrentRow)
CON.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
' Binding all fields
Public Sub ShowData(ByVal CurrentRow)
Try
TextBox1.Text = DST.Tables("Table1").Rows(CurrentRow)("ID")
DateTimePicker1.Text = DST.Tables("Table1").Rows(CurrentRow)("dob")
TextBox3.Text = DST.Tables("Table1").Rows(CurrentRow)("naam")
TextBox4.Text = DST.Tables("Table1").Rows(CurrentRow)("address")
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
' Fill Data
Public Sub filldatasetandview()
ds = New DataSet
dataadapter.Fill(ds, "Table1")
dv = New DataView(ds.Tables("Table1"))
cm = CType(Me.BindingContext(dv), CurrencyManager)
End Sub
' Binding all fields
Public Sub bindfields()
TextBox1.DataBindings.Clear()
DateTimePicker1.DataBindings.Clear()
TextBox3.DataBindings.Clear()
TextBox4.DataBindings.Clear()
TextBox1.DataBindings.Add("text", dv, "ID")
DateTimePicker1.DataBindings.Add("text", dv, "dob")
TextBox3.DataBindings.Add("text", dv, "naam")
TextBox4.DataBindings.Add("text", dv, "address")
End Sub
Private Sub cmdPre_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPre.Click
Try
If CurrentRow <> 0 Then
CurrentRow -= 1
ShowData(CurrentRow)
Else
MsgBox("This is the First Record...")
End If
Catch ex As Exception
MsgBox("No record to show")
End Try
End Sub
Private Sub cmdNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNext.Click
If CurrentRow = DST.Tables("Table1").Rows.Count - 1 Then
MsgBox("This is the Last Record...")
Else
CurrentRow += 1
ShowData(CurrentRow)
End If
End Sub
Private Sub cmdFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdFirst.Click
Try
CurrentRow = 0
ShowData(CurrentRow)
Catch ex As Exception
MsgBox("There is no record to show")
End Try
End Sub
Private Sub cmdLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLast.Click
CurrentRow = DST.Tables("Table1").Rows.Count - 1
ShowData(CurrentRow)
End Sub
End Class