Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA 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 March 18th, 2005, 01:23 AM
Authorized User
 
Join Date: Feb 2005
Posts: 14
Thanks: 0
Thanked 1 Time in 1 Post
Default AutoNumber Hell

Hello Everyone,

I need some assistence . This is my situation
I have a data base c:\\lms.mdb
where i have got a Table1 which have three fields ss,ss1,ss2 where
ss-AutoNumber
ss1-Text
ss2-Text

also for webcontrols in webform i have a dropdownlist from where a select names.

Now i am writing the code...........


using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;

namespace Wrox_United
{
    /// <summary>
    /// Summary description for WebForm2.
    /// </summary>
    public class WebForm2 : System.Web.UI.Page
    {
        protected System.Web.UI.WebControls.Button Button1;
        protected System.Web.UI.WebControls.Label Label1;
        protected System.Web.UI.WebControls.DropDownList DropDownList1;
        protected System.Web.UI.WebControls.Label Label2;

        private void Page_Load(object sender, System.EventArgs e)
        {
            // Put user code to initialize the page here
            if(!IsPostBack)
            {
                try
                {
                    OleDbConnection connection=new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\\lms.mdb");
                    connection.Open ();
                    OleDbCommand command=new OleDbCommand("select ss1 from Table1 ",connection);
                    OleDbDataReader reader= command.ExecuteReader ();
                    while(reader.Read())
                    {
                        DropDownList1.Items.Add (reader.GetString (0));
                    }
                    DropDownList1.DataBind ();
                    reader.Close ();
                    connection.Close ();
                }
                catch(Exception ex)
                {
                    Label2.Text =ex.Message.ToString();
                }
            }

        }

        #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
            base.OnInit(e);
        }

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.Button1.Click += new System.EventHandler(this.Button1_Click);
            this.Load += new System.EventHandler(this.Page_Load);

        }
        #endregion

        private void Button1_Click(object sender, System.EventArgs e)
        {

            string strNumber=null;
            Int32 intNumber=0;
            try
            {
                OleDbConnection connection=new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\\lms.mdb");
                connection.Open ();
                OleDbCommand command=new OleDbCommand("select ss,ss1 from Table1 where ss1='" + DropDownList1.SelectedItem.Value + "' ",connection);
                OleDbDataReader reader= command.ExecuteReader ();

                while(reader.Read())
                {
                    strNumber=Convert.ToString (reader.GetInt32(0));

                }
                //strNumber=Convert.ToString(intNumber);
                Label1.Text =strNumber;
                intNumber=Int32.Parse (strNumber);

                reader.Close ();
                connection.Close ();
            }
            catch(Exception ex)
            {
                Label2.Text =ex.Message.ToString();
            }


//------------------------------------------------------------------------------------------------------------------------------
            try
            {
                OleDbConnection connection1=new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\\lms.mdb");
                connection1.Open ();
                OleDbCommand cmd=new OleDbCommand ("update Table1 set ss2='No' where ss = '" + intNumber + "' ",connection1);
                OleDbDataReader r=cmd.ExecuteReader();

                r.Close ();
                connection1.Close();
            }
            catch(Exception ex)
            {
                Label2.Text =ex.Message.ToString();
            }


            }


        }


    }

-----------------
everytime i run the program i got the exception
:"Data type mismatch in criteria expression"

Please help why this exception is coming.
Thanks a million to anyone who solves this problem.
Also the values for the table 'Table1' is like this

ss ss1 ss2
--- --- ---
1 somjit nil
2 abhishek nil
3 prawin nil
4 arijit nil
5 lara nil
6 sachin Yes



Regards

Somissac

Kolkata,India

somissac
__________________
somissac
 
Old March 18th, 2005, 01:03 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

When you use the debugger, what line does this get stuck on?

mmcdonal
 
Old March 20th, 2005, 07:59 AM
Authorized User
 
Join Date: Mar 2005
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try review.

OleDbCommand command=new OleDbCommand("select ss,ss1 from Table1 where ss1='" + DropDownList1.SelectedItem.Value + "' ",connection);

The DropDownList.value should be the numeric position not the text of string type for criteria, as I know it. Am I too old?

 
Old March 22nd, 2005, 02:02 AM
Authorized User
 
Join Date: Feb 2005
Posts: 14
Thanks: 0
Thanked 1 Time in 1 Post
Default

I got the solution.
Thanks a lot.

somissac
 
Old March 22nd, 2005, 03:24 AM
Authorized User
 
Join Date: Mar 2005
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

And what was it?

 
Old March 22nd, 2005, 04:05 AM
Authorized User
 
Join Date: Feb 2005
Posts: 14
Thanks: 0
Thanked 1 Time in 1 Post
Default


The line is this:--

OleDbCommand command=new OleDbCommand("select ss,ss1 from Table1 where ss1='" + DropDownList1.SelectedItem.Value + "' ",connection);

Now the modified line should be:---
OleDbCommand command=new OleDbCommand("select ss,ss1 from Table1 where ss1=" + DropDownList1.SelectedItem.Value + " ",connection);

as ss1=Long Integer
and single quotes is for getting string values

somissac





Similar Threads
Thread Thread Starter Forum Replies Last Post
What Is dll Hell ? Bhalchandra VB Components 2 December 18th, 2006 03:23 PM
DLL Hell huanglanjing Access VBA 2 December 7th, 2006 11:13 AM
Circular Reference Hell! RFickling C# 1 November 7th, 2004 06:38 PM
Printing Hell (richTextBox) mrhyman VB How-To 4 February 18th, 2004 10:20 AM
ereg and eregi Hell! TreeWalker BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 1 June 21st, 2003 11:19 PM





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