SQL数据库和Visual Studio C#帮助。 [英] SQL Database and Visual Studio C# Help.

查看:74
本文介绍了SQL数据库和Visual Studio C#帮助。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Visual Studio,C#和SQL知之甚少。但我已经能够在我的计算机上安装VS和SQL。将2个数据库加载到SQL中(联系人列表,与联系人相关的Notes列表)。能够访问C#/ VStudio中的数据库。在2个单独的数据库中,ID#对应于联系人及其注释。 (我认为这就是你所说的主键?)



我能够按姓氏创建搜索,这样如果我搜索'SMI'我会得到在网格视图中以SMI开头的所有姓氏。



我试图得到它,以便如果我在网格视图中双击该行我可以使用该人的信息获得一个新的表单窗口,以及从其他数据库中提取相应的注释。



当我双击网格视图时我能够获得一个新的窗口形式,但它只加载来自联系人数据库的第1行的数据。



所以我想我想知道:

A)我可以编码什么来拉动点击的联系人。

B)如何从第二个数据库中调用相应的注释?



感谢您的帮助!

I know very little about Visual Studio, C#, and SQL. But i've been able to install VS and SQL on my computer. Loaded 2 databases into SQL (A list of Contacts, A list of Notes related to the Contacts). Able to access the databases in C#/VStudio. In the 2 separate databases there are ID# that correspond to the contact and their note. (I think that's what you call a primary key?)

I was able to create a search by last name so that if i search 'SMI' i'll get all the last names that start with 'SMI' in a grid view.

I'm trying to get it so that if I double click that row in grid view that I could get a new form window with that person's info, as well as pull in their corresponding note from the other database.

When I double click on the grid view i'm able to get a new window form but it loads only with the data from row #1 from the contact database.

So I guess i'm wondering:
A) What do I code to be able to pull the contact up that is clicked on.
B) How do I call the corresponding note from the second database?

Thank you for your help!

推荐答案

SQL代码非常简单:

The SQL code is pretty simple:
SELECT * FROM MyTable WHERE LastName LIKE 'SMI%'

将返回所有数据LastName字段以SMI开头 - '%'是SQL LIKE子句中的通配符,意思是任意数量的字符,就像'*'在Windows文件名中一样。因此以SMI结尾将是:

Will return all data where the LastName field starts with "SMI" - '%' is a wildcard in SQL LIKE clauses meaning "Any number of characters" just like '*' does in windows file names. So ending with "SMI" would be:

SELECT * FROM MyTable WHERE LastName LIKE '%SMI'



并且包含SMI将是:


And conatining "SMI" would be:

SELECT * FROM MyTable WHERE LastName LIKE '%SMI%'





要使用的C#代码更复杂,因为我们需要知道您正在使用的环境,以及如何首先加载表格。 (WinForms的代码将与WPF的代码或基于Web的方法不同,并且有许多方法可以访问SQL数据)



但是..我猜这是一个新的窗口形式,这是WinForms下的DataGridView。

所以处理 DataGridView.CellDoubleClick [ ^ ]事件,并使用RowIndex标识要显示的行。然后,您可以访问单元格数据,并将其传递给新表单的构造函数,以便使用ShowDialog方法显示。



有意义吗?



The C# code to use that is more complicated, as we need to know the environment you are working in, and how you are loading the table in the first place. (The code for WinForms will be different from the code for WPF, or a web based approach, and there are many ways of accessing the SQL data)

But...I'm guessing from "a new window form" that this is a DataGridView under WinForms.
So handle the DataGridView.CellDoubleClick[^] event, and use the RowIndex to identify the row to display. You can then access the cell data, and pass that to the constructor of your new form for display with the ShowDialog method.

Make sense?


这篇关于SQL数据库和Visual Studio C#帮助。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆