Wrox Programmer Forums
|
BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6
This is the forum to discuss the Wrox book ASP.NET 2.0 Instant Results by Imar Spaanjaars, Paul Wilton, Shawn Livermore; ISBN: 9780471749516
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 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 April 21st, 2009, 07:28 AM
Authorized User
 
Join Date: Jul 2008
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy SqlCommandBuilder

Hello everyone im trying to insert a record into a database but it displays the following error message:
The DataAdapter.SelectCommand.Connection property needs to be initialized;
Im using the following create function:

publicstring create(Docs dc)
{

//busl.tblDocumentRow r;
Dbconnection cd = newDbconnection();
SqlDataAdapter adp = newSqlDataAdapter("Select * From tblDocument", cd.con);
SqlCommandBuilder cmb = newSqlCommandBuilder(adp);
string msg;
busl.tblDocumentRow r = (busl.tblDocumentRow)ds.tblDocument.NewRow();
r.id = dc.id;
r.description = dc.description;
r.fpath = dc.filepath;
r.dc = dc.dc;
r.createdby = dc.usrC;
ds.tblDocument.Rows.Add(r);
//for all fields

adp.Update(ds.tblDocument);
ds.AcceptChanges();

msg =
"Success";
return msg;

}

This is the following connection class:

publicclassDbconnection
{
publicSqlConnection con;
public Dbconnection()
{
SqlConnection con = newSqlConnection("Data Source=MMS-AF4C3555D88/SQLEXPRESS;Initial Catalog=EDM;Integrated Security=True");
}
}

Thanks in advance
__________________
supertedz
 
Old April 21st, 2009, 06:09 PM
Friend of Wrox
 
Join Date: Jun 2007
Posts: 477
Thanks: 10
Thanked 19 Times in 18 Posts
Default

Does the connection work? If you comment out the database requests, will it open the page and display the Success message?
__________________
-------------------------

Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe

When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper

Chroniclemaster1, Founder of www.EarthChronicle.com
A Growing History of our Planet, by our Planet, for our Planet.









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