linking table from .mdf database to Sfchart in wpf

Hi guys. I was trying out this code sample from one of your pages  for linking to database using Microsoft.Jet.OLEDB.4.0 and it kept saying cannot read file type. Is there a way i can use the connection string in the app config file to display data in the Sfchart cause i already use this connection string to display data in the wpf data grid controls, the database extension is .mdf .

this is the connection string im using, <add name="NEXLOSSuper" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\DataLayer\NEXLOSR.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />



thanks in advance
////////////////////
<Grid x:Name="grid">
        <Grid.DataContext>
            <local:DataViewModel/>
        </Grid.DataContext>22
        <chart:SfChart>
            <chart:ColumnSeries ItemsSource="{Binding Data}" XBindingPath="ProductName" YBindingPath="UnitsInStock"></chart:ColumnSeries>
        </chart:SfChart>
 </Grid>

 

 C#

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
public class DataViewModel
    {
        DataSet dataset = new DataSet();
        public DataViewModel()
        {
            AddData();
        }
        public void AddData()
        {
            //Sets Database connection.
            string connectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0; Data Source={0}", @"..\..\Model\DataBase_File.mdb");
            OleDbConnection Connection = new OleDbConnection(connectionString);
            Connection.Open();
            OleDbCommand command = new OleDbCommand("Select Top 10 * from [Products]", Connection);
            OleDbDataAdapter DataAdapter = new OleDbDataAdapter(command);
            DataAdapter.Fill(dataset, "Product");
            //Sets the DataTable to Data property.
            this.Data = dataset.Tables["Product"];
            Connection.Close();
        }
        public DataTable _data;
        public DataTable Data
        {
            get
            {
                return _data;
            }
            set
            {
                _data = value;
            }
        }
    }
///////////////////////////////////////////

5 Replies

DS Durgadevi Selvaraj Syncfusion Team November 27, 2017 09:35 AM UTC

Hi Skanoko, 

Thanks for contacting Syncfusion Support. 

We have tried to reproduce the reported problem and unable to reproduced it at our end. However, we have prepared a sample based on this requirement (linking database with SfChart) and please find it from below link, 

Please find the output screenshot, 
 
If your requirement is different from the above please revert us with more information or modify the provided sample in order to reproduce the issue. It would be more helpful for us to provide a solution as sooner. 

Regards,  
Durgadevi S 




SS skanoko siame August 23, 2018 02:56 PM UTC

thanks the sample you sent me was most help full.

So data loads/shows in the chart from the database, but when i add new customer information, it wont show in the chart, unless i restart and reload the application again, based on the sample you sent me is it possible to show data to the chart in real or quick time, cause it would be cool if the appearence of the chart changed based on new data added. So ive zipped a copy of the code im using for you to have a look at where am i going wrong in terms of real-time feed back from the column chart. thanks in advance

Attachment: LSA.xaml_fa0ddc49.rar


MK Muneesh Kumar G Syncfusion Team August 24, 2018 07:06 AM UTC

Hi Skanoko siame, 
 
Thanks for your update. We have analyzed your requirement and we would like to inform you that there is no connection between database with series ItemsSource in application. So, we need to update the collection which is bind to series ItemsSource manually. You can achieve this requirement by changing the DataTable collection, which is bind to series ItemsSource as per the below code snippet. 
 
Code snippet [C#]: 
DispatcherTimer timer = new DispatcherTimer(); 
        DataViewModel viewModel = new DataViewModel(); 
        Random rd = new Random(); 
        string[] names; 
        public MainWindow() 
        { 
            InitializeComponent(); 
 
            series.ItemsSource = viewModel.Data; 
 
            names = new string[] { "Chang", "Ikura", "Kobe", "Peas", "Pepper" }; 
            timer.Start(); 
            timer.Tick += timer_Tick; 
            timer.Interval = new TimeSpan(0, 0, 0, 0, 100); 
        } 
        
        void timer_Tick(object sender, EventArgs e) 
        { 
            viewModel.Data.Rows.RemoveAt(0); 
            viewModel.Data.Rows.Add(new Object[] { names[rd.Next(0,4)], rd.Next(4,20) }); 
        } 
 
 
We have modified our sample based on this, please find the sample from the following location.  
 
 
Hope this helps. 
 
Regards, 
Muneesh Kumar G. 



SS skanoko siame August 31, 2018 02:06 PM UTC

Thanks again.

the changes you recomended are working in the prototype sample i made, but when i add those implementations to the main project and run it it simply just goes into break mode and it does not show any error of sorts in the lines of code

these are the changes i made that work in the prototype but not the main application

the project file is 136mb it wot fit in the upload limit

so ive put the esential files in a zip, have a look and see where im going wrong

thanks in advance.

///////////////////////////////////////
 public LSA()
        {
            InitializeComponent();

           // 

            //initialisation of loans grid
            dataGridViewX();
            PaymentsDueTodayX();
            PaymentsCompletedX();
            PaymentsDefaultedX();
            /////////////////////////////////

            //intelligent Core initialization point
            NewDefaultedCustomers();
            NewCompletedCustomers();
            ///////////////////////////////

           

            CustomerRegister();

            elpasswordelnombre();
            SecurityLogs();
            CollectedColateral();
            FinancesIssued();
            HandedoverColateral();

            //initialisation of loan roster
            LoansActiveV2();
            LoansCompletedV2();
            LoansDefectedV2();
            ////////////////////////////////
            //Views
            LoansIssuedTotal();
            VlalueColateral();

            ActiveLoan();
            CompletedLoan();
            DefaultedLoan();

            //realtime engine for chart
            //chartthread
           // ChartThread();
            //time thread
            ClockAndDate();


            textName.Text = Convert.ToString(NameID);

            SoundPlayer player = new SoundPlayer(Properties.Resources.Procyon);

            player.Play();

            stuffcat.ItemsSource = viewModel.Data;
            stuffcat3.ItemsSource = Datum.Data3;
            stuffcat4.ItemsSource = Detex.Data4;
            Series_1.ItemsSource = viewX.Data2;
            Series_2.ItemsSource = viewX.Data2;


            //EngAsNK2();

            //AI System
            EngAsync();
            //threadsystem          

           
        }

///////////////////////////////////////////////////////////////////////////


  private async void EngAsync()
        {


            for (; ; )
            {
                await Task.Delay(1000);
                textName.Text = ("Starting .....");
                await Task.Delay(1000);
                textName.Text = ("Starting ....");
                await Task.Delay(1000);
                textName.Text = ("Starting ...");
                await Task.Delay(1000);
                textName.Text = ("Starting ..");
                await Task.Delay(1000);
                textName.Text = ("Starting .");
                await Task.Delay(1000);
                textName.Text = ("Starting Other Tasks in the Background...");
                await Task.Delay(20000);
                textName.Text = ("Tasks Started....");
                await Task.Delay(5000);
                textName.Text = ("Payment state propagation started...");
                await Task.Delay(5000);
                dataGridViewX();
                textName.Text = ("---");
                await Task.Delay(5000);
                PaymentsCompletedX();
                textName.Text = ("--");
                await Task.Delay(5000);
                PaymentsDefaultedX();
                textName.Text = ("-");
                await Task.Delay(1000);
                textName.Text = ("Payment state propagation complete...");
                await Task.Delay(5000);
                textName.Text = ("Customer register Updating...");
                CustomerRegister();
                textName.Text = ("Customer register Update Complete...");
                await Task.Delay(5000);
                textName.Text = ("Checking of new admins started...");
                elpasswordelnombre();
                textName.Text = ("Checking of new admins Complete...");

                await Task.Delay(5000);
                textName.Text = ("Propergating Roster...");
                await Task.Delay(5000);
                LoansActiveV2();
                textName.Text = ("---");
                await Task.Delay(5000);
                LoansCompletedV2();
                textName.Text = ("--");
                await Task.Delay(5000);
                LoansDefectedV2();
                textName.Text = ("-");
                textName.Text = ("Roster Propagation Complete....");
                await Task.Delay(5000);
                textName.Text = ("Telemetry Propagation in process...");
                await Task.Delay(5000);
                LoansIssuedTotal();
                textName.Text = ("-------");
                await Task.Delay(5000);
                VlalueColateral();
                textName.Text = ("------");
                await Task.Delay(5000);
                ActiveLoan();
                textName.Text = ("-----");
                await Task.Delay(5000);
                CompletedLoan();
                textName.Text = ("----");
                await Task.Delay(5000);
                DefaultedLoan();
                textName.Text = ("---");
                await Task.Delay(5000);
                CollectedColateral();
                textName.Text = ("--");
                await Task.Delay(5000);
                FinancesIssued();
                textName.Text = ("-");
                await Task.Delay(5000);
                HandedoverColateral();
                textName.Text = ("Telemetry Propagation Complete...");
                await Task.Delay(5000);
                textName.Text = ("Chart Propagation Begining...");
                //-------------//      
                await Task.Delay(5000);
                //EngAsNK2();
                //viewModel.Data.Rows.RemoveAt(0);
                viewModel.Data.Rows.Add();
                //Datum.Data3.Rows.Add();
                //Detex.Data4.Rows.Add();
                //viewX.Data2.Rows.Add(); 
                //------------//
                textName.Text = ("Propagation Of Charts Complete..");
                await Task.Delay(5000);
                //------------//
                textName.Text = ("Now Sleeping, I will not disturb you.");
                await Task.Delay(5000);


            }
        }

//////////////////////////////////////////////////////////////////////////////




Attachment: LSA_Premium_399c3174.rar


MK Muneesh Kumar G Syncfusion Team September 5, 2018 12:05 PM UTC

Hi Skanoko siame,  
 
Thanks for your information.  
 
We have analyzed the provided files and checked the same with our sample. It works fine at our end. We suspect that the problem occurs due to each time new connection created while filtering the data. So, we suggest you to use a single connection string for all the data filter as per the below code snippet.  
 
Code snippet [C#]: 
        public MainWindow() 
        { 
            InitializeComponent(); 
 
          
            //Sets Database connection. 
            string connectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0; Data Source={0}", @"DataBase_File.mdb"); 
            Connection = new OleDbConnection(connectionString); 
            Connection.Open(); 
            .. 
 
            EngAsync(); 
 
            Connection.Close(); 
        } 
 
        private void dataGridViewX() 
        { 
             
            OleDbCommand command = new OleDbCommand("Select Top 10 * from [Data]", Connection); 
            OleDbDataAdapter DataAdapter = new OleDbDataAdapter(command); 
            DataAdapter.Fill(dataset, "Data"); 
            //Sets the DataTable to Data property. 
            Data = dataset.Tables["Data"]; 
 
            dataGrid2xc.ItemsSource = Data.DefaultView; 
 
            
        } 
        private void PaymentsCompletedX() 
        { 
            
            OleDbCommand command = new OleDbCommand("Select Top 10 * from [Data]", Connection); 
            OleDbDataAdapter DataAdapter = new OleDbDataAdapter(command); 
            DataAdapter.Fill(dataset, "Data"); 
            //Sets the DataTable to Data property. 
            Data = dataset.Tables["Data"]; 
 
            dataGrid2xy.ItemsSource = Data.DefaultView; 
 
        } 
  
We have modified our sample based on the provided files by you, please check the sample from the following location.  
 
 
If still you face the problem, please revert us by modifying the sample based on your application along with replication procedure. This would be helpful for us to give better solution in this. 
 
Regards, 
Muneesh Kumar G. 


Loader.
Up arrow icon