Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 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 December 31st, 2005, 05:26 PM
Authorized User
 
Join Date: Oct 2004
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default Inserting data into Access database

Hi Forum,

This code compiles and executes just fine, except the data is not inserted into the database. I think I need to make a commitment of some kind to finalize the transaction.

public void insertRow( Object s, EventArgs e )
{
   OleDbCommand cmd;
   String cmdString;
   String formValues;

   formValues = Email.Text + "," +
                Church.Text + "," +
             Name.Text + "," +
        Comments.Text;

   cmdString = "INSERT INTO GuestBook [VisitDate] VALUES (" + formValues + ")";

   connectDb();
   cmd = new OleDbCommand( cmdString, objConn );
   try{
    // not sure what to put here
   }/*catch( Object s ){
     // Handle error not sure what to do
   }*/
   finally {
    // not at all sure what to do next to commit transaction
   }
   objConn.Close();
}// End insertRow()

Thanks



 
Old December 31st, 2005, 06:26 PM
Authorized User
 
Join Date: Oct 2004
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Modified code as follows:

try{
 cmd.ExecuteCommand(); // error cs0122 here
}catch( Exception exception ){
 errorLable.Text = exception.ToString();
}
finally{ }
objConn.Close();

// get error
Compiler Error Message: CS0122: 'System.Data.OleDb.OleDbCommand.ExecuteCommand(Sys tem.Data.CommandBehavior, out object)' is inaccessible due to its protection level








Similar Threads
Thread Thread Starter Forum Replies Last Post
having problem in inserting in access database alto ASP.NET 2.0 Basics 4 May 24th, 2007 08:57 PM
Need help with inserting data into access database ITladybug ADO.NET 1 January 1st, 2006 01:50 PM
failure in inserting data into database ckmun81 Access ASP 3 December 21st, 2003 08:09 PM
Inserting data from Xml to Access Database diptanjan Classic ASP Professional 0 December 1st, 2003 02:05 AM





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