使用asp.net从sql server中的三个表中获取记录

编程入门 行业动态 更新时间:2024-10-22 18:33:25
本文介绍了使用asp从sql server中的三个表中获取记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在我的项目中我有三张桌子

调查(SurveyID,标题,描述)问题(QuestionID,SurveyID,Questiontext)选择(ChoiceId,QuestionID,Choicetext)

现在我想显示问题及其选项基于调查标题? i有一个调查标题下拉列表我想选择调查标题,其选项的问题应显示在数据网格上。 /> i想要做这样的查询

从选项中选择选择文本问题ID =从问题文本中选择问题ID =从问题中选择问题文本其中Surveytitle = dropdownlist.selectedvalue

i我没有在sql server中执行此操作的确切想法。 如何进行Sql查询这个? Plz帮助我... ...

解决方案

如果下拉列表绑定如下 dropdownlist.DataSourc e = dtServey dropdownlist.DisplayMember =Title dropdownlist.ValueMember =SurveyID dropdownlist.Databind();

查询应如下所示

选择 choicetext 从选择c INNER JOIN 问题q ON q.QuestionID = c.QuestionID INNER 加入调查s ON s.SurveyID = q.SurveyID 其中 s.SurveyID = @ SurveyID

下拉列表选择更改事件 传递@ SurveyID参数值dropdownlist.selectedvalue 快乐编码! :)

•设置时dropdownlist source,设置dropDown List.DataTextField = Title和dropDownList.DataValueField = SurveyID; •创建一个可以保存所选值的sql参数(调查ID) •加入问题和选择表基于调查ID •根据QuestionID使用GroupBy 了解更多关于Joins,sql参数的信息&查询

您好, 您可以编写如下所示的查询:

SELECT * FROM table_1 JOIN table_2 ON(table_2.table_1_id = table_1.table_1_id) JOIN table_3 ON(table_3.table_1_id = table_1.table_1_id)

问候, Shree M。

in my project i have three tables

Survey(SurveyID,Title,Description) Question(QuestionID,SurveyID,Questiontext) Choices(ChoiceId,QuestionID,Choicetext)

Now i want to show question and its option bases on the survey title? i have a dropdownlist of survey titles i want to select survey title and questions with its options should be shown on datagrid. i want to do some query like this

Select choicetext from Choices Where Question ID ="Select QuestionID From Questions Where Questiontext="Select Questiontext From Questions Where Surveytitle=dropdownlist.selectedvalue""

i am not geting the exact idea hoe to do this in sql server. How to make Sql Query of this? Plz Help ME Thnks...

解决方案

if dropdownlist is bind as below

dropdownlist.DataSource = dtServey dropdownlist.DisplayMember = "Title" dropdownlist.ValueMember = "SurveyID" dropdownlist.Databind();

Query should be like below

Select choicetext from Choices c INNER JOIN Questions q ON q.QuestionID = c.QuestionID INNER JOIN Survey s ON s.SurveyID = q.SurveyID Where s.SurveyID = @SurveyID

dropdownlist selection change event pass @SurveyID parameter value dropdownlist.selectedvalue Happy Coding! :)

• While setting the dropdownlist source, set the dropDownList.DataTextField = Title and dropDownList.DataValueField = SurveyID; • Create a sql parameter which can hold the selected value(survey ID) • Join the Questions & Choices table based on the survey ID • Use GroupBy based on QuestionID Read more about Joins, sql parameters & queries

Hi, You can write your query as shown below:

SELECT * FROM table_1 JOIN table_2 ON (table_2.table_1_id = table_1.table_1_id) JOIN table_3 ON (table_3.table_1_id = table_1.table_1_id)

Regards, Shree M.

更多推荐

使用asp.net从sql server中的三个表中获取记录

本文发布于:2023-10-16 00:24:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1495925.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:net   asp   server   sql

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!