Help me Pls..

Posted by Venkatu2005 under ASP.NET on 3/3/2008 | Views : 1482 | Status : [Member] | Replies : 5
Hi

can u give the solution pls
the string d is will written as public...

string d = DateTime.Today.ToShortDateString ();

int i=0;

cmd1 = new OleDbCommand("select count(*) from tbllvdate where uname='" + lbluname.Text + "' and mname='" + lblmname.Text + "' and vdate='"+d+"'", con);


i= Convert.ToInt32 (cmd1.ExecuteScalar());
if (i == 0)
{
lvd(); // this is the procedure to insert the record
}
else
{
Response.Write("Already Visited");
}

when i run this code i have the ERROR :

Data type mismatch in criteria expression.

pls give solution ...


Thanks.....




Responses

Posted by: Sagarp on: 1/25/2010 [Member] Bronze

Up
0
Down
string d = DateTime.Today.ToShortDateString ();
use it's work
int i=0;

cmd1 = new OleDbCommand("select count(*) from tbllvdate where uname=' " + lbluname.Text + " ' and mname=' " + lblmname.Text + " ' and vdate=' " + d + " ', con);


i= Convert.ToInt32 (cmd1.ExecuteScalar());
if (i == 0)
{
lvd(); // this is the procedure to insert the record
}
else
{
Response.Write("Already Visited");
}

Thanks
SagarP
http://www.emanonsolutions.net
http://emanonsolutions.blogspot.com/

Venkatu2005, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sabarimahesh on: 4/3/2012 [Member] Bronze | Points: 25

Up
0
Down
Hi

REF:http://www.access-programmers.co.uk/forums/showthread.php?t=86859

Life is a Race
Thanks & Regards
By
Sabari Mahesh P M

Venkatu2005, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Raja on: 3/3/2008 [Member] Starter

Up
0
Down
Hi,

First this is the suggestions. You should not use Sql statement like this instead you should use parameterized statement to avoid Sql Injection.
For tutorials on Parameterized statement, visit http://www.4guysfromrolla.com/webtech/092601-1.2.shtml

As far as your code is concern, better to write like this

object obj = cmd1.ExecuteScalar();

if (obj != null)
{
i = Convert.ToInt32(obj); // Means it retrun something and we are converting that to integer now
}
else
{
Response.Write("Already Exists");
}


Hope this will work.

Regards,
Raja, USA

Venkatu2005, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Venkatu2005 on: 3/3/2008 [Member] Starter

Up
0
Down
Hi

Raja

I had worked ur code againg i have the same problem once if i check the date with database

but again the data will be inserted.........



Venkatu2005, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Tahirmulani on: 3/19/2008 [Member] Starter

Up
0
Down
please check ur database query,
there is miss match between data type of date,

Venkatu2005, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response