locked
Query returning null even though the particular date is present RRS feed

  • Question

  • User804244510 posted

     I have a csv file which has columns date, occasion1 , occasion 2 etc I need to pull only certain data from the csv file.

    The code is shown below:


            string connString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=Text;", Server.MapPath("~"));
            DateTime? dat = null;
            string datt = "1/12/2012 12:00:00 AM";
           dat = Convert.ToDateTime(datt);
         
        
            string cmdString = string.Format("SELECT * FROM {0} where date = '" +dat+ " '" , "ausp.csv");
          

            OleDbDataAdapter dataAdapter = new OleDbDataAdapter(cmdString, connString);

            DataSet dataSet = new DataSet();

            dataAdapter.Fill(dataSet);
          
            //GridView1.DataSource = dataSet;
          
            //GridView1.DataBind();
             foreach(DataTable dataTable in dataSet.Tables)
             {
                 foreach(DataRow dataRow in dataTable.Rows)
             {
                     foreach (object value in dataRow.ItemArray)
                     {

                 Response.Write(value);
                 
                }
             
             }
                 break;
             }

    While running the code am getting the error

    No value given for one or more required parameters.

    which means that the query is returning null . But the date column has the specified date 1/12/2012 12:00:00 AM. Anybody please help me .It is very urgent :(

    Thanks in advance


         

    Tuesday, January 31, 2012 12:32 AM

Answers

  • User-2001765250 posted

    Dont set the Date as null type.by default date is system start date (1-1-1900 or 1-1-1970 as per system regional settings)

    so dont set it to null if blank then convert it to default date.

    I thnk the date you are getting form csv file is in different format so convert it to your database date format.



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 31, 2012 2:21 AM
  • User3866881 posted

    string cmdString = string.Format("SELECT * FROM {0} where date = '" +dat+ " '" , "ausp.csv")

    Hello:)

    Set a breakpoint there at the statement to see what's happening?And what's the result of cmdString?

    As far as I see,For an Access Database's datetime。You should:

    1)Make sure that the type of the specific column is DateTime。

    2)Then use # instead of single quote——Something like this following:

    "select * from xxx where [date]=#"+datetimevalue+"#"

    Reguards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 1, 2012 7:54 PM

All replies

  • User1829879277 posted

    First of all try without where clause. If it succeeds then you need to check the format of the dates being compared. Both the formats should be same.

    Tuesday, January 31, 2012 1:14 AM
  • User804244510 posted

    It is working perfectly fine , without using where clause . The format of dates is also the same . !!!

    Tuesday, January 31, 2012 1:34 AM
  • User1829879277 posted

    Kindly confirm whether there is any event at which dates are matching like, date = '1/12/2012 12:00:00 AM'

    You may test it by hard coding the query as:

    string cmdString = string.Format("SELECT * FROM {0} where date = '1/12/2012 12:00:00 AM'" , "ausp.csv");
    Tuesday, January 31, 2012 1:52 AM
  • User-2001765250 posted

    Dont set the Date as null type.by default date is system start date (1-1-1900 or 1-1-1970 as per system regional settings)

    so dont set it to null if blank then convert it to default date.

    I thnk the date you are getting form csv file is in different format so convert it to your database date format.



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 31, 2012 2:21 AM
  • User3866881 posted

    string cmdString = string.Format("SELECT * FROM {0} where date = '" +dat+ " '" , "ausp.csv")

    Hello:)

    Set a breakpoint there at the statement to see what's happening?And what's the result of cmdString?

    As far as I see,For an Access Database's datetime。You should:

    1)Make sure that the type of the specific column is DateTime。

    2)Then use # instead of single quote——Something like this following:

    "select * from xxx where [date]=#"+datetimevalue+"#"

    Reguards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 1, 2012 7:54 PM