Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Visual Basic 2005 Basics
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 19th, 2006, 01:41 AM
Registered User
 
Join Date: Oct 2006
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
 
Old October 25th, 2006, 08:38 PM
Registered User
 
Join Date: Oct 2006
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


 
Old November 27th, 2006, 08:32 AM
Authorized User
 
Join Date: Nov 2006
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





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 08:34 AM
SQL Server 2000 and SQL Server 2000 CE dparsons SQL Server 2000 1 July 31st, 2006 12:59 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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.