|
-
Mar 7th, 2012, 09:29 AM
#1
Thread Starter
New Member
oledbexception data error
sirs,
I am a newbie to vb. i some how with some help constructed a code. but when i start running it, it shows an error "system.data.oledb.oledbexception" and with a caption not a valid filename. i have created an access db file in c:\Documents and Settings\User\Mydocuments\Student1.mdb. i cant figure out what could be the reason. Please help me sir in this.
thanking you in advance
Charu
-
Mar 8th, 2012, 09:28 AM
#2
Thread Starter
New Member
Re: oledbexception data error
this is the code i have written
Public Class Form1
Dim cnn As OleDb.OleDbConnection
Dim cmd As OleDb.OleDbCommand
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cnn = New OleDb.OleDbConnection()
cnn.ConnectionString = "Provider=Microsoft.Jet.Oledb.4.0; Data Source=" & Application.StartupPath & "c:\Documents and Settings\User\My Documents\student1.mdb"
End Sub
Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
Me.Close()
End Sub
Private Sub refreshdata()
Dim dt As DataTable
If Not cnn.State = ConnectionState.Open Then
'open connection
cnn.Open()
Dim da As New OleDb.OleDbDataAdapter("select studentid as [id]," & _
"studentname as [name], course,college,place,phone" & _
"from student1 order by studentid", cnn)
cmd.Connection = cnn
dt=New DataTable()
da.Fill(dt)
cnn.Close()
Use dt to grid or other controls
End If
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cmd As OleDb.OleDbCommand
If Not cnn.State = ConnectionState.Open Then
'open connection if it is not open yet
cnn.Open() <--- error here
cmd=New OleDb.OleDbCommand()
cmd.Connection = cnn
'add data to table
cmd.CommandText = "insert into student1 (studentid,studentname,course,college,place,phone)" & _
"Values(" & Me.TextBox1.Text & " , '" & Me.TextBox2.Text & "', '" & Me.TextBox3.Text & "','" _
& Me.TextBox4.Text & "', '" & Me.TextBox5.Text & "'," & Me.TextBox6.Text & ")"
cmd.ExecuteNonQuery()
'refresh data
Refreshdata()
'close connection
cnn.Close()
End If
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
Me.TextBox1.Text = ""
Me.TextBox2.Text = ""
Me.TextBox3.Text = ""
Me.TextBox4.Text = ""
Me.TextBox5.Text = ""
Me.TextBox6.Text = ""
Me.TextBox1.Focus()
End Sub
End Class
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|