From 17a59f37bf7b9ad2f2a1e33431d05df8ed767983 Mon Sep 17 00:00:00 2001 From: Priyadharshini-Sf4862 Date: Fri, 16 May 2025 16:31:14 +0530 Subject: [PATCH 1/3] Updated sample and readme file --- README.md | 8 +- SQLWithChart/App.config | 6 - SQLWithChart/App.xaml.cs | 7 +- SQLWithChart/AssemblyInfo.cs | 10 ++ SQLWithChart/MainWindow.xaml | 8 +- SQLWithChart/MainWindow.xaml.cs | 46 +----- SQLWithChart/Properties/AssemblyInfo.cs | 55 ------- SQLWithChart/Properties/Resources.Designer.cs | 71 --------- SQLWithChart/Properties/Resources.resx | 117 --------------- SQLWithChart/Properties/Settings.Designer.cs | 30 ---- SQLWithChart/Properties/Settings.settings | 7 - SQLWithChart/SQLWithChart.csproj | 139 ++---------------- SQLWithChart/SQLWithChart.csproj.user | 14 ++ SQLWithChart/SQLWithChart.sln | 17 +-- SQLWithChart/ViewModel.cs | 43 ++++++ 15 files changed, 103 insertions(+), 475 deletions(-) delete mode 100644 SQLWithChart/App.config create mode 100644 SQLWithChart/AssemblyInfo.cs delete mode 100644 SQLWithChart/Properties/AssemblyInfo.cs delete mode 100644 SQLWithChart/Properties/Resources.Designer.cs delete mode 100644 SQLWithChart/Properties/Resources.resx delete mode 100644 SQLWithChart/Properties/Settings.Designer.cs delete mode 100644 SQLWithChart/Properties/Settings.settings create mode 100644 SQLWithChart/SQLWithChart.csproj.user create mode 100644 SQLWithChart/ViewModel.cs diff --git a/README.md b/README.md index be859b0..a89552e 100644 --- a/README.md +++ b/README.md @@ -71,4 +71,10 @@ public class ViewModel ![SQL DataBinding to WPF SfChart](https://user-images.githubusercontent.com/53489303/200743338-52fee1f9-d723-46b2-87ae-81da3b6e2067.png) -KB article - [How to bind the SQL Database to WPF Charts?](https://www.syncfusion.com/kb/11595/how-to-bind-the-sql-database-to-wpf-charts) +## Troubleshooting + +#### Path too long exception + +If you are facing a path too long exception when building this example project, close Visual Studio and rename the repository to a shorter name before building the project. + +For more details, refer to the KB on [How to bind the SQL Database to WPF Charts?](https://www.syncfusion.com/kb/11595/how-to-bind-the-sql-database-to-wpf-charts) diff --git a/SQLWithChart/App.config b/SQLWithChart/App.config deleted file mode 100644 index bbb5314..0000000 --- a/SQLWithChart/App.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/SQLWithChart/App.xaml.cs b/SQLWithChart/App.xaml.cs index d9d46a7..7fbeaa0 100644 --- a/SQLWithChart/App.xaml.cs +++ b/SQLWithChart/App.xaml.cs @@ -1,9 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Configuration; +using System.Configuration; using System.Data; -using System.Linq; -using System.Threading.Tasks; using System.Windows; namespace SQLWithChart @@ -14,4 +10,5 @@ namespace SQLWithChart public partial class App : Application { } + } diff --git a/SQLWithChart/AssemblyInfo.cs b/SQLWithChart/AssemblyInfo.cs new file mode 100644 index 0000000..b0ec827 --- /dev/null +++ b/SQLWithChart/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/SQLWithChart/MainWindow.xaml b/SQLWithChart/MainWindow.xaml index 5bb8bdc..0956e40 100644 --- a/SQLWithChart/MainWindow.xaml +++ b/SQLWithChart/MainWindow.xaml @@ -2,11 +2,12 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:chart="clr-namespace:Syncfusion.UI.Xaml.Charts;assembly=Syncfusion.SfChart.WPF" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:SQLWithChart" - xmlns:chart="http://schemas.syncfusion.com/wpf" mc:Ignorable="d" Title="MainWindow" Height="450" Width="800"> + @@ -24,9 +25,10 @@ + XBindingPath="xval" + YBindingPath="yval"/> + diff --git a/SQLWithChart/MainWindow.xaml.cs b/SQLWithChart/MainWindow.xaml.cs index b4c445a..9280189 100644 --- a/SQLWithChart/MainWindow.xaml.cs +++ b/SQLWithChart/MainWindow.xaml.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Data; -using System.Data.SqlClient; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; @@ -27,40 +21,4 @@ public MainWindow() InitializeComponent(); } } - - public class ViewModel - { - public ViewModel() - { - try - { - SqlConnection thisConnection = new SqlConnection(ConnectionString); - thisConnection.Open(); - string Get_Data = "SELECT * FROM ChartData"; - SqlCommand cmd = thisConnection.CreateCommand(); - cmd.CommandText = Get_Data; - SqlDataAdapter sda = new SqlDataAdapter(cmd); - DataSet ds = new DataSet(); - sda.Fill(ds); - var table = ds.Tables[0]; - this.DataTable = table; - } - catch - { - MessageBox.Show("DataBase Error"); - } - } - - public object DataTable { get; set; } - - public static string ConnectionString - { - get - { - string currentDir = System.Environment.CurrentDirectory; - currentDir = currentDir.Substring(0, currentDir.Length - 10) + "\\LocalDataBase"; - return @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=" + currentDir + @"\SeriesItemsSource.mdf;Integrated Security=True"; - } - } - } -} +} \ No newline at end of file diff --git a/SQLWithChart/Properties/AssemblyInfo.cs b/SQLWithChart/Properties/AssemblyInfo.cs deleted file mode 100644 index cfb247b..0000000 --- a/SQLWithChart/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,55 +0,0 @@ -using System.Reflection; -using System.Resources; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Windows; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("SQLWithChart")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("SQLWithChart")] -[assembly: AssemblyCopyright("Copyright © 2020")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -//In order to begin building localizable applications, set -//CultureYouAreCodingWith in your .csproj file -//inside a . For example, if you are using US english -//in your source files, set the to en-US. Then uncomment -//the NeutralResourceLanguage attribute below. Update the "en-US" in -//the line below to match the UICulture setting in the project file. - -//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] - - -[assembly: ThemeInfo( - ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located - //(used if a resource is not found in the page, - // or application resource dictionaries) - ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located - //(used if a resource is not found in the page, - // app, or any theme specific resource dictionaries) -)] - - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/SQLWithChart/Properties/Resources.Designer.cs b/SQLWithChart/Properties/Resources.Designer.cs deleted file mode 100644 index 68b8c67..0000000 --- a/SQLWithChart/Properties/Resources.Designer.cs +++ /dev/null @@ -1,71 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace SQLWithChart.Properties -{ - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources - { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() - { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager - { - get - { - if ((resourceMan == null)) - { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SQLWithChart.Properties.Resources", typeof(Resources).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture - { - get - { - return resourceCulture; - } - set - { - resourceCulture = value; - } - } - } -} diff --git a/SQLWithChart/Properties/Resources.resx b/SQLWithChart/Properties/Resources.resx deleted file mode 100644 index ffecec8..0000000 --- a/SQLWithChart/Properties/Resources.resx +++ /dev/null @@ -1,117 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/SQLWithChart/Properties/Settings.Designer.cs b/SQLWithChart/Properties/Settings.Designer.cs deleted file mode 100644 index 9d186ab..0000000 --- a/SQLWithChart/Properties/Settings.Designer.cs +++ /dev/null @@ -1,30 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace SQLWithChart.Properties -{ - - - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] - internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase - { - - private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); - - public static Settings Default - { - get - { - return defaultInstance; - } - } - } -} diff --git a/SQLWithChart/Properties/Settings.settings b/SQLWithChart/Properties/Settings.settings deleted file mode 100644 index 8f2fd95..0000000 --- a/SQLWithChart/Properties/Settings.settings +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/SQLWithChart/SQLWithChart.csproj b/SQLWithChart/SQLWithChart.csproj index 45325d4..1f4cf73 100644 --- a/SQLWithChart/SQLWithChart.csproj +++ b/SQLWithChart/SQLWithChart.csproj @@ -1,139 +1,26 @@ - - - + + - Debug - AnyCPU - {458298CB-BA74-40E8-88CF-E8ED7CD6B927} WinExe - SQLWithChart - SQLWithChart - v4.6 - 512 - {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 4 - true - true - publish\ - true - Disk - false - Foreground - 7 - Days - false - false - true - 0 - 1.0.0.%2a - false - false - true + net9.0-windows + enable + enable + true - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - - - 4.0 - - - - - - - - MSBuild:Compile - Designer - - - MSBuild:Compile - Designer - - - App.xaml - Code - - - MainWindow.xaml - Code - - + - - Code - - - True - True - Resources.resx - - - True - Settings.settings - True - - - ResXFileCodeGenerator - Resources.Designer.cs - - - SettingsSingleFileGenerator - Settings.Designer.cs - + + - - - - - - - - SeriesItemsSource.mdf - Always - Always + - - False - Microsoft .NET Framework 4.6 %28x86 and x64%29 - true - - - False - .NET Framework 3.5 SP1 - false - + + - + diff --git a/SQLWithChart/SQLWithChart.csproj.user b/SQLWithChart/SQLWithChart.csproj.user new file mode 100644 index 0000000..644b0a6 --- /dev/null +++ b/SQLWithChart/SQLWithChart.csproj.user @@ -0,0 +1,14 @@ + + + + + + Designer + + + + + Designer + + + \ No newline at end of file diff --git a/SQLWithChart/SQLWithChart.sln b/SQLWithChart/SQLWithChart.sln index 76873c7..e934953 100644 --- a/SQLWithChart/SQLWithChart.sln +++ b/SQLWithChart/SQLWithChart.sln @@ -1,9 +1,9 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.29709.97 +# Visual Studio Version 17 +VisualStudioVersion = 17.12.35527.113 d17.12 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SQLWithChart", "SQLWithChart.csproj", "{458298CB-BA74-40E8-88CF-E8ED7CD6B927}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SQLWithChart", "SQLWithChart.csproj", "{C2C13C43-76F0-4E32-A678-0A7448E06DE2}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -11,15 +11,12 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {458298CB-BA74-40E8-88CF-E8ED7CD6B927}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {458298CB-BA74-40E8-88CF-E8ED7CD6B927}.Debug|Any CPU.Build.0 = Debug|Any CPU - {458298CB-BA74-40E8-88CF-E8ED7CD6B927}.Release|Any CPU.ActiveCfg = Release|Any CPU - {458298CB-BA74-40E8-88CF-E8ED7CD6B927}.Release|Any CPU.Build.0 = Release|Any CPU + {C2C13C43-76F0-4E32-A678-0A7448E06DE2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C2C13C43-76F0-4E32-A678-0A7448E06DE2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C2C13C43-76F0-4E32-A678-0A7448E06DE2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C2C13C43-76F0-4E32-A678-0A7448E06DE2}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {4867E04D-34CB-458F-B28D-25E63B762D16} - EndGlobalSection EndGlobal diff --git a/SQLWithChart/ViewModel.cs b/SQLWithChart/ViewModel.cs new file mode 100644 index 0000000..d889cfc --- /dev/null +++ b/SQLWithChart/ViewModel.cs @@ -0,0 +1,43 @@ +using Microsoft.Data.SqlClient; +using System.Data; +using System.Windows; + +namespace SQLWithChart +{ + + public class ViewModel + { + public ViewModel() + { + try + { + SqlConnection thisConnection = new SqlConnection(ConnectionString); + thisConnection.Open(); + string Get_Data = "SELECT * FROM ChartData"; + SqlCommand cmd = thisConnection.CreateCommand(); + cmd.CommandText = Get_Data; + SqlDataAdapter sda = new SqlDataAdapter(cmd); + DataSet ds = new DataSet(); + sda.Fill(ds); + var table = ds.Tables[0]; + this.DataTable = table; + } + catch + { + MessageBox.Show("DataBase Error"); + } + } + + public object DataTable { get; set; } + + public static string ConnectionString + { + get + { + string currentDir = System.Environment.CurrentDirectory; + currentDir = currentDir.Substring(0, currentDir.Length - 10) + "\\LocalDataBase"; + return @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=" + currentDir + @"\SeriesItemsSource.mdf;Integrated Security=True"; + } + } + } +} From 6d8cce466accd44d4296900735ec6dfcaa9f129c Mon Sep 17 00:00:00 2001 From: Priyadharshini-Sf4862 Date: Thu, 22 May 2025 13:27:57 +0530 Subject: [PATCH 2/3] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a89552e..74f7a0a 100644 --- a/README.md +++ b/README.md @@ -77,4 +77,4 @@ public class ViewModel If you are facing a path too long exception when building this example project, close Visual Studio and rename the repository to a shorter name before building the project. -For more details, refer to the KB on [How to bind the SQL Database to WPF Charts?](https://www.syncfusion.com/kb/11595/how-to-bind-the-sql-database-to-wpf-charts) +For more details, refer to the KB on [How to bind the SQL Database to WPF Charts](https://www.syncfusion.com/kb/11595/how-to-bind-the-sql-database-to-wpf-charts) From dafab088d8bc412fd4f7c71dec33c363a508827d Mon Sep 17 00:00:00 2001 From: Priyadharshini-Sf4862 Date: Mon, 9 Jun 2025 12:31:21 +0530 Subject: [PATCH 3/3] Delete SQLWithChart/SQLWithChart.csproj.user --- SQLWithChart/SQLWithChart.csproj.user | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 SQLWithChart/SQLWithChart.csproj.user diff --git a/SQLWithChart/SQLWithChart.csproj.user b/SQLWithChart/SQLWithChart.csproj.user deleted file mode 100644 index 644b0a6..0000000 --- a/SQLWithChart/SQLWithChart.csproj.user +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - Designer - - - - - Designer - - - \ No newline at end of file