如何使用WPF,C#和XAML建立与数据库的连接

时间:2022-02-12 18:55:14

I started developing simple application in WPF and XAML.

我开始在WPF和XAML中开发简单的应用程序。

I want to try accessign the sql server database and display the data from stored procedure onto the UI form.

我想尝试访问sql server数据库并将存储过程中的数据显示到UI表单上。

I have a table called parentProject -> idParentProject (pk), txtParentProjName varchar(max). my SP is parentProj_sp -> select * from parentProject. n I want to use a dropdown list in which, If the sp returns say (3) records, then dropdownlist should have those 3 records retreived from sp.

我有一个名为parentProject的表 - > idParentProject(pk),txtParentProjName varchar(max)。我的SP是parentProj_sp - > select * from parentProject。我想使用一个下拉列表,其中,如果sp返回说(3)个记录,那么dropdownlist应该从sp中重新获得那3个记录。

similar manner, I have subproject -> idsubproject(pk), idParentProject , txtSubProjectName varchar(max), dateProjstart, dateprojectend.

类似的方式,我有子项目 - > idsubproject(pk),idParentProject,txtSubProjectName varchar(max),dateProjstart,dateprojectend。

once the parentprojectname is selected from first dropdown, then, subproject dropdown should be enabled and it should have the subprojectnames for the corresponding parent project.

一旦从第一个下拉列表中选择了parentprojectname,那么应该启用子项目下拉列表,它应该具有相应父项目的子项目名称。

my sp is subproject_sp -> SELECT dtProjectStart, dtProjectEnd FROM tblSubProject WHERE (idParentProject = @idProjectIndex).

我的sp是subproject_sp - > SELECT dtProjectStart,dtProjectEnd FROM tblSubProject WHERE(idParentProject = @idProjectIndex)。

please help me how to connect to database in C# using WPF and XAML.

请帮助我如何使用WPF和XAML连接到C#中的数据库。

Thank You, Ramm

谢谢你,拉姆

3 个解决方案

#1


2  

1) Select the technology you want to use to access the database. (Hint: It's not WPF w/XAML)

1)选择要用于访问数据库的技术。 (提示:这不是WPF w / XAML)

2) Read the documentation for that particular technology.

2)阅读该特定技术的文档。

3) Use the documented behavior to create your connection and do what you need to do.

3)使用记录的行为来创建连接并执行您需要执行的操作。

4) Profit!

Your question clearly indicates that you don't understand the technology stack you're working with. You need to return to basics and grasp what WPF, XAML, and databases are, as well as how they interact.

您的问题清楚地表明您不了解您正在使用的技术堆栈。您需要返回基础并掌握WPF,XAML和数据库的内容,以及它们如何交互。

#2


1  

Try ScottGu's great series on Linq to Sql which is probably the easiest way to get started IMHO. http://weblogs.asp.net/scottgu/archive/2007/07/16/linq-to-sql-part-5-binding-ui-using-the-asp-linqdatasource-control.aspx

试试ScottGu关于Linq to Sql的精彩系列,这可能是开始恕我直言的最简单方法。 http://weblogs.asp.net/scottgu/archive/2007/07/16/linq-to-sql-part-5-binding-ui-using-the-asp-linqdatasource-control.aspx

Or for more in depth study http://msdn.microsoft.com/en-us/library/bb425822.aspx

或者更深入的研究http://msdn.microsoft.com/en-us/library/bb425822.aspx

#3


0  

You will want to combine two technologies. Data Acess and Data Binding. For Data Acess use one of Ado.Net, Linq2Sql, or what the rest of your group prefers.

您将需要结合两种技术。数据访问和数据绑定。对于Data Acess,请使用Ado.Net,Linq2Sql或其他人喜欢的内容。

#1


2  

1) Select the technology you want to use to access the database. (Hint: It's not WPF w/XAML)

1)选择要用于访问数据库的技术。 (提示:这不是WPF w / XAML)

2) Read the documentation for that particular technology.

2)阅读该特定技术的文档。

3) Use the documented behavior to create your connection and do what you need to do.

3)使用记录的行为来创建连接并执行您需要执行的操作。

4) Profit!

Your question clearly indicates that you don't understand the technology stack you're working with. You need to return to basics and grasp what WPF, XAML, and databases are, as well as how they interact.

您的问题清楚地表明您不了解您正在使用的技术堆栈。您需要返回基础并掌握WPF,XAML和数据库的内容,以及它们如何交互。

#2


1  

Try ScottGu's great series on Linq to Sql which is probably the easiest way to get started IMHO. http://weblogs.asp.net/scottgu/archive/2007/07/16/linq-to-sql-part-5-binding-ui-using-the-asp-linqdatasource-control.aspx

试试ScottGu关于Linq to Sql的精彩系列,这可能是开始恕我直言的最简单方法。 http://weblogs.asp.net/scottgu/archive/2007/07/16/linq-to-sql-part-5-binding-ui-using-the-asp-linqdatasource-control.aspx

Or for more in depth study http://msdn.microsoft.com/en-us/library/bb425822.aspx

或者更深入的研究http://msdn.microsoft.com/en-us/library/bb425822.aspx

#3


0  

You will want to combine two technologies. Data Acess and Data Binding. For Data Acess use one of Ado.Net, Linq2Sql, or what the rest of your group prefers.

您将需要结合两种技术。数据访问和数据绑定。对于Data Acess,请使用Ado.Net,Linq2Sql或其他人喜欢的内容。