Npgsql PostgresException
Hi, I have the following codes:
MainWindow.xaml.cs:
using Syncfusion.Windows.Shared;
using Syncfusion.Windows.Tools.Controls;
using System.Windows;
namespace SyncfusionWpfDropdownTest
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
string selectedCountry = "";
string selectedMarket = "";
string selectedDeliveryMonth = "";
Date selectedStartDate = new Date();
Date selectedEndDate = new Date();
public MainWindow()
{
InitializeComponent();
}
private void DropDownMenuItem_CountryClick(object sender, RoutedEventArgs e)
{
selectedCountry = (sender as DropDownMenuItem)?.Header?.ToString()?? string.Empty;
CountryDropDown.Label = selectedCountry;
viewModel.CountrySavedValue = selectedCountry;
}
private void DropDownMenuItem_MarketClick(object sender, RoutedEventArgs e)
{
selectedMarket = (sender as DropDownMenuItem)?.Header?.ToString()?? string.Empty;
MarketDropDown.Label = selectedMarket;
viewModel.MarketSavedValue = selectedMarket;
}
private void DropDownMenuItem_DeliveryMonthClick(object sender, RoutedEventArgs e)
{
selectedDeliveryMonth = (sender as DropDownMenuItem)?.Header?.ToString()?? string.Empty;
DeliveryMonthDropDown.Label = selectedDeliveryMonth;
viewModel.DeliveryMonthSavedValue = selectedDeliveryMonth;
}
private void ButtonAdvItem_ChartButtonClick(object sender, RoutedEventArgs e)
{
string selectedMarket = viewModel.MarketSavedValue;
string selectedDeliveryMonth = viewModel.DeliveryMonthSavedValue;
ChartWindow chartWindow = new ChartWindow(selectedMarket, selectedDeliveryMonth);
chartWindow.Title = $"{selectedMarket} - {selectedDeliveryMonth}";
chartWindow.Show();
}
private void ButtonAdvItem_TableButtonClick(object sender, RoutedEventArgs e)
{
string selectedCountry = viewModel.CountrySavedValue;
List<Date> startDates = DateCalendarEditStart.SelectedDatesList;
List<Date> endDates = DateCalendarEditEnd.SelectedDatesList;
Date selectedStartDate = startDates.Min();
Date selectedEndDate = endDates.Max();
TableWindow tableWindow = new TableWindow(selectedCountry, selectedStartDate, selectedEndDate);
tableWindow.Title = $"{selectedCountry}";
tableWindow.Show();
}
}
}
TableViewModel.cs:
using System.Collections.ObjectModel;
using Npgsql;
using Syncfusion.PMML;
using Syncfusion.ProjIO;
using Syncfusion.Windows.Shared;
namespace SyncfusionWpfDropdownTest
{
public class TableViewModel
{
private string _countrySavedValue = string.Empty;
private Date _startDateSavedValue;
private Date _endDateSavedValue;
public ObservableCollection<Country> Countries { get; set; }
public ObservableCollection<StartDate> StartDates { get; set; }
public ObservableCollection<EndDate> EndDates { get; set; }
public string CountrySavedValue
{
get { return _countrySavedValue; }
set { _countrySavedValue = value; }
}
public Date StartDateSavedValue
{
get { return _startDateSavedValue; }
set { _startDateSavedValue = value; }
}
public Date EndDateSavedValue
{
get { return _endDateSavedValue; }
set { _endDateSavedValue = value; }
}
public ObservableCollection<EconomicCalendar> EconomicCalendars { get; set; }
public TableViewModel()
{
Countries = new ObservableCollection<Country>();
StartDates = new ObservableCollection<StartDate>();
EndDates = new ObservableCollection<EndDate>();
EconomicCalendars = new ObservableCollection<EconomicCalendar>();
LoadData();
}
public void LoadData()
{
NpgsqlConnection conn = new NpgsqlConnection("Host=192.168.1.2; Port=5432; Database=tradingapp; Username=vorlket; Password=Vcsokr.");
conn.Open();
string query = "SELECT Title, Country, Period, DateTime, Indicator, Importance, Actual, Previous, Forecast, \"Raw Actual\", \"Raw Previous\", \"Raw Forecast\", " +
"Ticker, Category, Currency, Source, \"Source URL\", Comment FROM EconomicCalendar WHERE Country = '" + CountrySavedValue + "' AND DateTime >= '" + StartDateSavedValue + "' AND DateTime::date <= '" + EndDateSavedValue + "'";
NpgsqlCommand cmd = new NpgsqlCommand(query, conn);
NpgsqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
EconomicCalendars.Add(new EconomicCalendar
{
Title = reader.GetString(0),
Country = reader.GetString(1),
Period = reader.GetString(2),
DateTime = reader.GetDateTime(3),
Indicator = reader.GetString(4),
Importance = reader.GetInt32(5),
Actual = reader.GetString(6),
Previous = reader.GetString(7),
Forecast = reader.GetString(8),
RawActual = reader.GetString(9),
RawPrevious = reader.GetString(10),
RawForecast = reader.GetString(11),
Ticker = reader.GetString(12),
Category = reader.GetString(13),
Currency = reader.GetString(14),
Source = reader.GetString(15),
SourceUrl = reader.GetString(16),
Comment = reader.GetString(17)
});
}
}
}
}
When I select the country, startdate and enddate values and click the TableButton, I get the following error:
Could you please help me figuring out what's going on or how to debug this program?
Thanks.
SIGN IN To post a reply.
2 Replies
1 reply marked as answer
KJ
Kook Jin Noh
August 12, 2024 04:05 AM UTC
string query = "SELECT Title, Country, Period, DateTime, Indicator, Importance, Actual, Previous, Forecast, \"Raw Actual\", \"Raw Previous\", \"Raw Forecast\", " +
"Ticker, Category, Currency, Source, \"Source URL\", Comment FROM EconomicCalendar WHERE Country = '" + CountrySavedValue + "' AND DateTime >= TO_CHAR(TO_DATE('" + StartDateSavedValue.ToString() + "', 'DD-MM-YYYY'), 'YYYY-MM-DD')::date AND DateTime <= TO_CHAR(TO_DATE('" + EndDateSavedValue.ToString() + "', 'DD-MM-YYYY'), 'YYYY-MM-DD')::date";
resolved the issue.
Marked as answer
JS
Jayashree Suresh Anand
Syncfusion Team
August 13, 2024 06:33 AM UTC
Hi Kook,
We are glad you found the solution, feel free to open a new forum thread for any new issue that may arise. We will be happy to help you!
Regards,
Jayashree
SIGN IN To post a reply.
- 2 Replies
- 2 Participants
- Marked answer
-
KJ Kook Jin Noh
- Aug 11, 2024 10:23 AM UTC
- Aug 13, 2024 06:33 AM UTC