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
|