954,557 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Student. Need help with DataGridView items saving to access.

Hello everyone this will be my first post.
I am happy that there is a forum like this with very supportive people.:)

So on topic..
I am a student creating an Inventory System software for my school using VB on VS 2008.
I am having trouble saving items from a DataGridView to Access 2007.

The codes I browsed here are quite different from what instructors teach us at our school.

These are some of the codes we are using to save items from textboxes to Access 2007 database with a table named studenttable and database named student for your added information.

Dim StudentAdapter as New OledbDataAdapter
Dim StudentBuilder as New OleDBCommandBuilder
Dim StudentDS as New DataSet
Dim con as New OleDbConnection

       con.ConnectionString = "Provider = Microsoft.Ace.Oledb.12.0; Data Source = student.accdb"
        con.Open()

StudentAdapter = New OleDbDataAdapter("Select * from studenttable", con)
StudentBuilder = New OleDbCommandBuilder(StudentAdapter)
StudentAdapter .Fill(StudentDS , "StudentInfo")

Dim newrow As DataRow = StudentDS.Tables("StudentInfo").NewRow()
                newrow("StudentID") = textbox1.Text
                newrow("Name") = textbox2.Text
                StudentDS .Tables("StudentInfo").Rows.Add(newrow)
                StudentAdapter .Update(StudentDS , "StudentInfo")


See? Totally different from what i am seeing here.. >_<.
Hoping for replies. Thank you. :)

bunik34
Newbie Poster
6 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

Hi there,
welcome to our community , which i think that you will find very helpfull.

Now on topic,

instead of :

StudentAdapter .Update(StudentDS , "StudentInfo")


Try this:

StudentAdapter .Fill(StudentDS)


Here's another piece of code, that i was using to add a row into my DB:

OleDbConnection Con = new OleDbConnection(ConnectionString);
		DataSet ds = new DataSet();
		OledbDataAdapter da = new OledbDataAdapter("INSERT INTO StudentInfo(StudentId, Name) VALUES('"+textbox1.Text+"','"+textbox2.Text+"')",Con);
try
  {
    da.Fill(ds);
  }
catch(Exception ex)
  {
    'Write exception handling code here!
  }


Hope i helped,
Alex. :)

Alexpap
Junior Poster
121 posts since Sep 2008
Reputation Points: 11
Solved Threads: 13
 

Thank you. This really helped.
But I think the "StudentAdapter.Fill(StudentDS)" doesn't fill up the access 2007 database.

bunik34
Newbie Poster
6 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 
Thank you. This really helped. But I think the "StudentAdapter.Fill(StudentDS)" doesn't fill up the access 2007 database.

Did you try it? Were there any exceptions thrown?

Alexpap
Junior Poster
121 posts since Sep 2008
Reputation Points: 11
Solved Threads: 13
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: