Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Visual Basic 2005 Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old October 19th, 2006, 01:41 AM
Registered User
 
Join Date: Oct 2006
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Add records from a DataGridView to SQL Server 2000

I'm having a problem here.

I have a window application form created using Visual Studio 2005.The form contains a Add Button and a DataGridView.

How do we code in such a way that the data entered in DataGridView columns are added into the SQL Server Database ? And hope to receive steps on how to do so.

Hope to receive reply soon.


Rgds
Tracy
Reply With Quote
  #2 (permalink)  
Old October 25th, 2006, 08:38 PM
Registered User
 
Join Date: Oct 2006
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi everyone,

I'm doing a form created from Visual Studio 2005 which contain a "Add" button and a DataGridView. If the records are successfully added, it will be inserted into the SQL server database.

I am trying to insert records from DataGridView into my SQL Server database without retrieving any information and I do not require to retrieve records from database. Initally, the database in SQL Server is empty. For this program, I made use of the SqlDataAdapter, DataSet and BindingSource.


This is my latest codings as listed below:

Dim sqlcom As SqlCommand = New SqlCommand()
Dim da As New SqlDataAdapter("SELECT * FROM TBReqDG", sqlcon)
Dim myDataSet As New DataSet()
Dim cb As New SqlCommandBuilder(da)
da.InsertCommand = cb.GetInsertCommand()
da.Update(myDataSet, "TBReqDG") 'ERROR COMES FROM HERE
'Open connection, execute the commands
 sqlcon.Open()
 sqlcom.Connection = sqlcon
'Close Connection
sqlcon.Close()


As my program runs, it show this error:
Update unable to find TableMapping['TBReqDG'] or DataTable 'TBReqDG'.

I don't know where it had gone wrong and hope anyone who knows is able to guide me along.
Hope to receive reply soon as itís urgent & thanks. =):D

Regards
Tracy


Reply With Quote
  #3 (permalink)  
Old November 27th, 2006, 07:32 AM
Authorized User
 
Join Date: Nov 2006
Location: , , USA.
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ef1196
Default

When you issue the da.Update command you are listing "TBRegDG" as a table alias that has not yet been created. You first need to "fill" the dataset as follows:

da.Fill(MyDataSet,"TBRegDG")

When you "Fill" a dataset with the contents of your select command you can call the table within that dataset anything you wish (in the example above you would be using the real name of the table).





Best Regards,
Earl Francis
Reply With Quote
Reply


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How To Read And Add Image to Sql 2000 ??? nsr2007nsr Pro VB.NET 2002/2003 1 February 5th, 2007 07:34 AM
SQL Server 2000 and SQL Server 2000 CE dparsons SQL Server 2000 1 July 31st, 2006 12:59 PM
Can't locate SQL Server 2000 database with Add Con fredrated Visual Web Developer 2005 0 February 27th, 2006 05:06 PM
looking for access 2000 to sql server 2000 sql/que method SQL Server 2000 0 July 7th, 2005 12:46 PM
SQL SERVER 2000 AND ACCESS 2000 ckentebe SQL Server 2000 3 June 17th, 2004 08:50 PM



All times are GMT -4. The time now is 07:47 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.