Home > DeveloperSection > Forums > ASP.Net don't match the Access Date/Time Column
jacob rasel
jacob rasel

Total Post:88

Points:616
Posted on    January-16-2015 10:23 PM

 ASP.Net C#  MS Access 
Ratings:


 1 Reply(s)
 542  View(s)
Rate this:

I'm trying to sort for today. I am giving match error while I am comparing.

OleDbConnection baglanti = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\Dragonfly\\Documents\\Visual Studio 2013\\WebSites\\WebSite2\\App_Data\\calismagunluk.mdb");

OleDbDataReader oku;

OleDbCommand sorgu =new OleDbCommand();

DateTime bugun = DateTime.Now.Date;

sorgu.CommandText = "select * from calisan where kulID=" + sesionKulId +

    " AND gun='" + bugun + "' ";

 oku = sorgu.ExecuteReader();//I give error in here

    if (oku.HasRows) {

    Repeater1.DataSource = oku;

    Repeater1.DataBind();

    oku.Dispose();}

    else{

        Repeater1.Visible = false;

        repeaterBos.Text = "Bugün Hiç Çalışma Yapmamışsınız...";

        oku.Dispose();

    }

I am getting this error: "Data type mismatch in criteria expression".

If I change the db column to Text, it is working. But I don't want it this way. How should I follow the way?



Hugh Jackman
Hugh Jackman

Total Post:52

Points:366
Posted on    January-16-2015 10:54 PM

You can bypass the format problem and let the command work the format by itself by using parameters:

OleDbConnection baglanti = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\Dragonfly\\Documents\\Visual Studio 2013\\WebSites\\WebSite2\\App_Data\\calismagunluk.mdb");

OleDbDataReader oku;

OleDbCommand sorgu =new OleDbCommand();

DateTime bugun = DateTime.Now.Date;

sorgu.CommandText = "select * from calisan where kulID=@ID AND gun=@date";

sorgu.Parameters.Add("@ID", OleDbType.Integer).Value = susionKulId;

sorgu.Parameters.Add("@date", OleDbType.DBTimeStamp).Value = bugun; 


Don't want to miss updates? Please click the below button!

Follow MindStick