I have a form that filters/sorts data from a database and displays it in a useful format. The user is suppose to enter a date range (using 2 datetimepickers, they select a start and end date for the search) and a product model to narrow down the data.
I'm running into an issue trying to apply the date range they select to the query that pulls the data. I'm somehow messing up my To_Timestamp but I haven't been able to figure out how. I have a feeling I'm missing something really simple or fundamental if searching google didn't bring it up. What am I missing here?
For some more context, I'm taking the entered dates and parsing them as datetimes then using those datetimes in the query. EDIT: So I did a quick check to see if the Between was my issue. I still get an error after getting rid of it. The error goes away when the Where part of the query is commented out. So there's still some issue with my To_Timestamp. EDIT2: I attempted the parameterizing the query and ran into an issue doing so for the date range I'm using. Since the user is selected a start and a stop date for the search, there are 2 dates to set := to the datetime from the database. The way the query is written now, I believe the date is just being overwritten. How would I go about encompassing a date range within the parameterization?
public static DataTable MBHQuery(string stringFrom, string stringTo, string Model)
{
string HString =
@" SELECT
HEADER_ID,
SET model=:Model,
series,
short_name,
SET published_dttm=:StringFrom,
SET published_dttm=:StringTo,
VALID_DTTM,
FROM
MBH
WHERE
wbh1.PUBLISHED_DTTM >= StringFrom AND
wbh1.PUBLISHED_DTTM <= StringTo";
DataTable Hdtbl = null;
if(IsConnected()) {
try {
string HQuery = string.Format(HString, StringFrom, StringTo, Model);
OracleCommand Hcmd = new OracleCommand(HQuery, gmb.ServerConnection.oracleConnection);
Hcmd.BindByName = true;
Hcmd.Parameters.Add("StringFrom", StringFrom);
Hcmd.Parameters.Add("StringTo", StringTo);
Hcmd.Parameters.Add("engineModel", engineModel);
OracleDataAdapter HdataAdapter = new(Hcmd);
Hdtbl = new DataTable("HEADER");
HdataAdapter.Fill(Hdtbl);
}
catch(Exception ex) {
using ExceptionDialog exDialog = new(ex);
exDialog.ShowDialog();
Hdtbl = null;
}
}
//This is called from a different file
public void PullDataTables_Click(object sender, EventArgs e)
{
DateTime MBdtpFromdt = this.MBdtpFrom.Value.Date;
DateTime MBdtpTodt = this.MBdtpTo.Value.Date;
string MBdtpFromstr = MBdtpFromdt.ToString("YYYY-MM-DD H:mm:ss");
string MBdtpTostr = MBdtpTodt.ToString("YYYY-MM-DD H:mm:ss");
gmb.ServerConnection.MBHQuery(MBdtpFromstr, MBdtpTostr, Model.Text);