
05-03-2012, 11:37 PM
|
|
Newcomer
|
|
Join Date: May 2008
Posts: 10
|
|
vb .net database error
|
Hey guys, you have finally convinced me to switch to .net after 10+ years of vb6 I have made the switch. I have been trying to get the database sample to work. I have been unable to figure it out. I posted my code below, but something isn't working right and I cant figure it out. Please review my code if you have a chance and let me know what I am doing wrong. I am having a really hard time understanding the dataset,dataadapter, etc etc. I am looking for some help and maybe some working code samples that I can play with to try to teach myself. I keep getting this error in the sample : Value of type 'WindowsApplication1.testDataSetTableAdapters.studentsTableAdapter' cannot be converted to 'System.Data.OleDb.OleDbDataAdapter'
Thanks for your help! matt
Code:
Imports System.IO
Imports System.Data.OleDb
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'student_data_DataSet.students' table. You can move, or remove it, as needed.
Me.StudentsTableAdapter.Fill(Me.student_data_DataSet.students)
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
' Setup a command builder so that we can talk to the data adapter.
Dim commandBuilder As New OleDb.OleDbCommandBuilder(StudentsTableAdapter)
Dim newRow As DataRow
newRow = student_data_DataSet.Tables("students").NewRow
' Add columns for each item.
newRow.Item("Student Name") = TextBox1.Text
' Add the new row to the table in the student_data_DataSet.
student_data_DataSet.Tables("").Rows.Add(newRow)
' Write the changes to the database.
StudentsTableAdapter.Update(Me.student_data_DataSet, "students")
MessageBox.Show("New student added to the database.")
End Sub
End Class
These are the lines that are throwing the errors
"Dim commandBuilder As New OleDb.OleDbCommandBuilder(StudentsTableAdapter)"
and
StudentsTableAdapter.Update(Me.student_data_DataSet, "students")
both are throwing the same error. I took some quick screen shots to show : http://imgur.com/a/dddHP
|
|