Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET 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, 03:48 AM
Authorized User
 
Join Date: Feb 2005
Posts: 14
Thanks: 0
Thanked 1 Time in 1 Post
Default Getting Data Type mismatch for autonumber

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
__________________
somissac
 
Old March 18th, 2005, 04:49 AM
Authorized User
 
Join Date: Jul 2004
Posts: 68
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to aravwind Send a message via Yahoo to aravwind
Default

what is the datatype declared for ss2
 
Old March 18th, 2005, 07:46 AM
Authorized User
 
Join Date: Feb 2005
Posts: 14
Thanks: 0
Thanked 1 Time in 1 Post
Default

Well , ihave commited the mistake so i must find the answer
I have written in the query expression
OleDbCommand cmd=new OleDbCommand)"update Table1 set ss2='No' where ss='" + (System.Int32)intNumber + "' ",connection);

well it is wrong syntax

it should be.........
OleDbCommand cmd=new OleDbCommand)"update Table1 set ss2='No' where ss=" + (System.Int32)intNumber + " ",connection);

The single quotes shouldn't be there ain't it as we are dealing with number.

Thanks and Regards.


somissac
 
Old March 18th, 2005, 07:49 AM
Authorized User
 
Join Date: Feb 2005
Posts: 14
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
quote:Originally posted by aravwind
 what is the datatype declared for ss2
The datatype for ss2 is text.
Regards


somissac
 
Old March 1st, 2006, 12:02 AM
Registered User
 
Join Date: Feb 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to Tammy Chong
Default

Hai..

Now i am facing the same situation where i get this mismatch problem. I think is cause by this field called "ss". Is that a integer field? Change that datatype to text.

Hope that can help.

:)






Similar Threads
Thread Thread Starter Forum Replies Last Post
Data type mismatch sharon5469 ASP.NET 1.0 and 1.1 Basics 2 May 27th, 2007 10:01 AM
data type mismatch karma SQL Language 3 April 6th, 2006 07:58 AM
Data type mismatch problem dominic_huang Classic ASP Databases 3 November 15th, 2004 03:12 AM
Data Type mismatch error clueless_may Access VBA 1 May 5th, 2004 09:16 AM
Data Type Mismatch error transcona Classic ASP Databases 4 June 25th, 2003 07:23 PM





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