Click here to Skip to main content
15,943,233 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi....
am accessing data from ms access database between two dates.am entering dates from textboxes for selection using where clause.in database date datatype id date/time format. So am getting error like datatype mismatch!
how can i do this.help me
Posted

C#
DateTime dt = DateTime.Parse(myTextBox.Text);

Or
C#
DateTime dt;
if !(DateTime.TryParse(myTextBox.Text, out dt))
   {
   // Report problem to user
   }
 
Share this answer
 
Try this Link[^]
 
Share this answer
 
Hi...
Finally,am find the solution to it.like blow.
C#
string fromdate = txtfdt.Text;
          DateTime fdt = Convert.ToDateTime(fromdate);

          string todate = txttdt.Text;
          DateTime tdt = Convert.ToDateTime(todate);


          con = new OleDbConnection(cs);
          cmd = new OleDbCommand("select * from DateWise where Date between @FDT and @TDT ", con);
          //cmd.CommandType = CommandType.Text;
          cmd.Parameters.AddWithValue("@FDT", fdt);
          cmd.Parameters.AddWithValue("@TDT", tdt);
          con.Open();
          cmd.ExecuteNonQuery();
          OleDbDataAdapter da = new OleDbDataAdapter(cmd);
          //DataSet ds = new DataSet();
          //DataTable dt = new DataTable();
          System.Data.DataTable dt = new System.Data.DataTable();
          da.Fill(dt);
          con.Close();

that textbox values are passed like parameters.thank u.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900