Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET Database and Reporting > vb .net database error


Reply
 
Thread Tools Display Modes
  #1  
Old 05-03-2012, 11:37 PM
mattdahack mattdahack is offline
Newcomer
 
Join Date: May 2008
Posts: 10
Default 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
Reply With Quote
  #2  
Old 05-04-2012, 08:31 AM
PlausiblyDamp's Avatar
PlausiblyDamp PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Wigan, UK
Posts: 1,678
Default

The CommandBuilder object expects you to pass in an OleDbDataAdapter but you are giving it a StudentsTableAdapter object, the two aren't compatible - hence the error.

Out of interest is there a reason you are using the ComandBuilder with the StudentsTableAdapter as the designer should have already created methods for Insert, Update and Delete anyway.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #3  
Old 05-04-2012, 10:48 AM
mattdahack mattdahack is offline
Newcomer
 
Join Date: May 2008
Posts: 10
Default

Out of plain stupidity....I just started vb.net ater 10+ years of vb legacy so I am trying to learn the entire program at once. 90 degree learning "curve". How can I have vb generate the methods for update add delete etc...? I tried using the wizard but these are the results I got. Who knows though maybe I used the wizard wrong too. Any help would be welcome as I am crashing and burning on this new .net.
Reply With Quote
  #4  
Old 05-04-2012, 11:31 AM
PlausiblyDamp's Avatar
PlausiblyDamp PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Wigan, UK
Posts: 1,678
Default

If you are using the DataSet designer (which you are because it creates the strongly typed table adapters) it should create the insert, update and delete methods automatically.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #5  
Old 05-04-2012, 12:17 PM
mattdahack mattdahack is offline
Newcomer
 
Join Date: May 2008
Posts: 10
Default

I am just going to start fresh here because nothing is working.
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
 
 
-->