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 May 24th, 2007, 01:30 AM
Registered User
 
Join Date: May 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default having problem in inserting in access database


   I am having problem in inserting and updating into access database.It showing the following message "Syntax error in UPDATE statement" and for insert "Syntax error in INSERT INTO statement". I have a dropdownlist id=listcolour, the item selected from dropdownlist will be inserted into the database. I am giving the progarm for ur reference. the language used is C#

    protected void btninsert_Click(object sender, EventArgs e)
    {
        string insertSql = "INSERT INTO wire_master(product_code, description, colour, opening_stock, rate, value, unit) VALUES('" + txtpcode.Text + "','" + txtdescription.Text + "','" + listcolour.SelectedItem.Text + "','" + txtopstock.Text + "','" + txtrate.Text + "','" + txtvalue.Text + "','" + txtunit.Text + "')";

        con = new OleDbConnection(constr);
        cmd = new OleDbCommand(insertSql, con);
        cmd.CommandType = CommandType.Text;
        int added = 0;

        try
        {
            con.Open();
            added = cmd.ExecuteNonQuery();
            result.Text = "<b>" + added.ToString() + "</b>" + " record added.";
        }
        catch (Exception ex)
        {
            result.Text = "<b>Error in entering data. </b>" + ex.Message;
        }
        finally
        {
            con.Close();
        }

    }
    protected void btnupdate_Click(object sender, EventArgs e)
    {
        string updateSql = "UPDATE wire_master SET description='" + txtdescription.Text + "', colour='" + listcolour.SelectedItem.Text + "', opening_stock='" + txtopstock.Text + "', rate='" + txtrate.Text + "', value='" + txtvalue.Text + "', unit='" + txtunit.Text + "' WHERE product_code='" + txtpcode.Text + "'";

        con = new OleDbConnection(constr);
        cmd = new OleDbCommand(updateSql, con);
        cmd.CommandType = CommandType.Text;

        int updated = 0;

        try
        {
            con.Open();
            updated = cmd.ExecuteNonQuery();
            result.Text = "<b>" + updated.ToString() + "</b>" + "<b> record updated.</b>";
        }
        catch (Exception ex)
        {
            result.Text = "<b>Error updating database.</b>" + ex.Message;
        }
        finally
        {
            con.Close();
        }
  }

  Plz solve the problem.




 
Old May 24th, 2007, 07:32 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there..

you are passing every field as a text field.. is that correct???

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old May 24th, 2007, 08:43 AM
Registered User
 
Join Date: May 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have taken every field in database as text. So passing every field as text.

 
Old May 24th, 2007, 09:06 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

ok.. then another thing to try is debug the code, once you build the query (insert, update) take that and try it inside the database you are using to get a more comprehensive error....

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old May 24th, 2007, 08:57 PM
Registered User
 
Join Date: May 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi gbianchi,
   The problem is solved, problem was is column name value, once I changed the name to val it worked. However thanx for ur cooperation.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem inserting multilingual text into database salim C# 0 May 5th, 2007 11:11 AM
Need help with inserting data into access database ITladybug ADO.NET 1 January 1st, 2006 01:50 PM
Inserting data into Access database OldCoder ASP.NET 2.0 Basics 1 December 31st, 2005 06:26 PM
Inserting data from Xml to Access Database diptanjan Classic ASP Professional 0 December 1st, 2003 02:05 AM
Problem In Inserting Records in database zaeem Classic ASP Databases 1 October 22nd, 2003 06:35 AM





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