6 Replies - 2290 Views - Last Post: 16 January 2009 - 11:38 AM Rate Topic: -----

#1 afridi2129  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 66
  • Joined: 04-November 07

oledb error: Data type mismatch

Posted 16 January 2009 - 06:46 AM

hi... i want to read typename column from database... but it gives an error of data type miss match...

in database TID is number , and typename is text...prgram should read the textbox1's value and then search for that TID in database ..and according to that tid will read typename... this is the relation..

whenever i try to read a number it happens specially in autonumbers if any one have any tutorial then plz paste a link... thanx....

Posted Image

 private void button1_Click_1(object sender, EventArgs e)
		{
			OleDbConnection conn = new OleDbConnection("Provider=Microsoft.jet.OLEDB.4.0;Data source=data.mdb");

			try
			{
				conn.Open();
			}
			catch (OleDbException ex)
			{
				Console.WriteLine("ERROR: {0}", ex.Message);
			}

			string str = "select TypeName from CandieType where TID='" + textBox1.Text + "'";

			OleDbCommand command = new OleDbCommand(str, conn);
			OleDbDataReader reader = command.ExecuteReader();

			while (reader.Read())
			{

				textBox3.Text = reader["TypeName"].ToString();

			}
			reader.Close();

			try
			{
				conn.Close();
			}
			catch (OleDbException ex)
			{
				Console.WriteLine("ERROR: {0}", ex.Message);
			}
		}


Is This A Good Question/Topic? 0
  • +

Replies To: oledb error: Data type mismatch

#2 dklingman  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 33
  • View blog
  • Posts: 263
  • Joined: 23-December 08

Re: oledb error: Data type mismatch

Posted 16 January 2009 - 07:03 AM

it's because you are searching TID as a string value

TID='2' is a string

make is so that it is

TID=2 NOTICE NO QUOTES


that's why you're getting data type mismatch error because it's a string instead of a number

This post has been edited by dklingman: 16 January 2009 - 07:03 AM

Was This Post Helpful? 0
  • +
  • -

#3 afridi2129  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 66
  • Joined: 04-November 07

Re: oledb error: Data type mismatch

Posted 16 January 2009 - 07:26 AM

thanx for reply but still error...
i tried this as u said..

string str = "select TypeName from CandieType where TID= " + texbox1.Text + "'";



but error
Syntax error in string in query expression 'TID= 2''.

then i tried to convert like this
string str = "select TypeName from CandieType where TID= " + Convert.ToInt64(textBox1.Text) + "'";



but still same Syntax error in string in query expression 'TID= 2''.
Was This Post Helpful? 0
  • +
  • -

#4 dklingman  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 33
  • View blog
  • Posts: 263
  • Joined: 23-December 08

Re: oledb error: Data type mismatch

Posted 16 January 2009 - 07:27 AM

look at your code you still have a single quote at the end of the sql statement
Was This Post Helpful? 0
  • +
  • -

#5 afridi2129  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 66
  • Joined: 04-November 07

Re: oledb error: Data type mismatch

Posted 16 January 2009 - 07:34 AM

ooopsssssss...sorry Sir...

it works...thanxxxxx alot...
Was This Post Helpful? 0
  • +
  • -

#6 dklingman  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 33
  • View blog
  • Posts: 263
  • Joined: 23-December 08

Re: oledb error: Data type mismatch

Posted 16 January 2009 - 07:34 AM

not a problem and any time ;)
Was This Post Helpful? 0
  • +
  • -

#7 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: oledb error: Data type mismatch

Posted 16 January 2009 - 11:38 AM

Modified title to be more descriptive of the problem.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1