Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 反转join命令_Asp.net_Sql Server_Vb.net_Webforms - Fatal编程技术网

Asp.net 反转join命令

Asp.net 反转join命令,asp.net,sql-server,vb.net,webforms,Asp.net,Sql Server,Vb.net,Webforms,我正在接管一个用asp.NETVB编写的项目,我正在使用mssql 我有一个文本框,其中包含设施的文本值(FacName) 我想做的是,当用户单击submit时,程序会获取文本框中输入的文本,查找facilities表,找到facilities名称,将facility ID与之匹配,并更新Inction facility ID列 这是我的两张桌子: Episode Facilities ID__________FacilityID | ID_____

我正在接管一个用asp.NETVB编写的项目,我正在使用mssql

我有一个文本框,其中包含设施的文本值(FacName)

我想做的是,当用户单击submit时,程序会获取文本框中输入的文本,查找facilities表,找到facilities名称,将facility ID与之匹配,并更新Inction facility ID列

这是我的两张桌子:

Episode                   Facilities

ID__________FacilityID   |   ID__________FacName
1___________10           |   10__________Beenleigh
2___________14           |   14__________Sunnybank
3___________15           |   15__________Brisbane
用户更新该插曲以指向另一个设施-假设他们希望插曲ID“2”引用一个新设施,在本例中为“Brisbane”

他们在文本框中输入Brisbane并点击submit,然后在事件表中的结果变成:

Episode                   Facilities

ID__________FacilityID   |   ID__________FacName
1___________10           |   10__________Beenleigh
2___________15           |   14__________Sunnybank
3___________15           |   15__________Brisbane
因此,它是在facilities表中进行查找,并返回facilities.id,然后在inception.FacilityID列中使用该值

我已经让我的select语句运行良好,希望它能帮助任何渴望回答我问题的人

工作选择语句

 SELECT Episode.ID, Episode.NOCSID, Episode.Disease, Episode.PHUID,     
        Episode.Status, Episode.Date, Episode.PersonID, Episode.ChangeType, 
        Episode.ChangeBy, Episode.ChangeDate, Episode.DoctorID, 
        Episode.FacilityID, Episode.OnsetDate, Episode.CloseDate, 
        Episode.Duplicate, Episode.OutbreakID, Episode.ClinicalLead, 
        Episode.NextActionDate, Facilities.FacName, Facilities.ID AS Expr1 
        FROM Episode 
        LEFT OUTER JOIN Facilities 
        ON Episode.FacilityID = Facilities.ID WHERE (Episode.ID = @ID)
不工作更新语句:

UPDATE Episode
SET NOCSID = @NOCSID,
    Disease = @Disease,
    PHUID = @PHUID,
    Status = @Status,
    PersonID = @PersonID,
    ChangeType = 'Updated',
    ChangeBy = @ChangeBy,
    ChangeDate = GETDATE(),
    DoctorID = @DoctorID,
    OnsetDate = @OnsetDate,
    CloseDate = @CloseDate,
    Duplicate = @Duplicate,
    OutbreakID = @OutbreakID,
    ClinicalLead = @ClinicalLead,
    NextActionDate = @NextActionDate,
    FacilityID = @FacilityID
FROM Episode
INNER JOIN Facilities
  ON Episode.FacilityID = Facilities.FacName
WHERE (Episode.ID = @original_ID)
AND (Episode.NOCSID = @original_NOCSID
OR Episode.NOCSID IS NULL
AND @original_NOCSID IS NULL)
AND (Episode.Disease = @original_Disease)
AND (Episode.PHUID = @original_PHUID)
AND (Episode.Status = @original_Status)
AND (Episode.PersonID = @original_PersonID
OR Episode.PersonID IS NULL
AND @original_PersonID IS NULL)
AND (Episode.DoctorID = @original_DoctorID
OR Episode.DoctorID IS NULL
AND @original_DoctorID IS NULL)
AND (Episode.FacilityID = @original_FacilityID
OR Episode.FacilityID IS NULL
AND @original_FacilityID IS NULL)
AND (Episode.OnsetDate = @original_OnsetDate
OR Episode.OnsetDate IS NULL
AND @original_OnsetDate IS NULL)
AND (Episode.CloseDate = @original_CloseDate
OR Episode.CloseDate IS NULL
AND @original_CloseDate IS NULL)
AND (Episode.Duplicate = @original_Duplicate
OR Episode.Duplicate IS NULL
AND @original_Duplicate IS NULL)
AND (Episode.OutbreakID = @original_OutbreakID
OR Episode.OutbreakID IS NULL
AND @original_OutbreakID IS NULL)
AND (Episode.ClinicalLead = @original_ClinicalLead
OR Episode.ClinicalLead IS NULL
AND @original_ClinicalLead IS NULL)
AND (Episode.NextActionDate = @original_NextActionDate
OR Episode.NextActionDate IS NULL
AND @original_NextActionDate IS NULL)

好吧,这就是我最后要做的:

因为我使用的jquery下拉列表也使用了ashx处理程序,所以我有我需要的设施名称,我只需要ID名称,这样我就可以在提交时将ID发布回数据库。因此,我修改了sql命令以引入ID和设施名称,如下所示:

  Public Class Search_VB : Implements IHttpHandler

Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
    Dim prefixText As String = context.Request.QueryString("q")
    Dim conn As SqlConnection = New SqlConnection
    conn.ConnectionString = ConfigurationManager _
            .ConnectionStrings("CDI").ConnectionString
    Dim cmd As SqlCommand = New SqlCommand
    cmd.CommandText = ("select ID, FacName from Facilities where FacName like '%' + @SearchText + '%'")


    cmd.Parameters.AddWithValue("@SearchText", prefixText)
    cmd.Connection = conn
    Dim sb As StringBuilder = New StringBuilder

    conn.Open()
    Dim sdr As SqlDataReader = cmd.ExecuteReader
    While sdr.Read
        sb.Append(sdr("FacName") & (" ID: "))
        sb.Append(sdr("ID")).Append(Environment.NewLine)


    End While
    conn.Close()
    context.Response.Write(sb.ToString)

End Sub
所以现在我有了我的设备id,我需要抓取设备id准备发回

因此,我在页面的脚本标记中更新了以下内容:

<script type="text/javascript">
    //the code below gets the jquery drop down working, and uses the ashx handler to feed it results to populate the list
    $(document).ready(function () {
        $('[id$=txt_Search]').autocomplete('/Facility_Search.ashx');


        //monitor for when the user clicks the update button.
        $("[id$=Button1]").click(function () {

            //fetch the selected value from the text box
            FacNameTextValue = $('[id$=txt_Search]').val()
            //pull off the prefix (the facility name, leaving only the characters after the : character, this should
            //only leave the facility ID
            FacNameTextValue = FacNameTextValue.substring(FacNameTextValue.indexOf(":") + 2);
            //Filter everything out except numbers
            FacNameTextValue = FacNameTextValue.replace(/\D/g, '');
            // Now if the string is empty, we need to alert the user that no Facility match was found, and they need to create a new one.


            //Now populate the text box with the filtered facility ID
            document.getElementsByName('DetailsViewEpisodeEdit$FacilityIDTextBox')[0].value = FacNameTextValue;
            //alert is for debug purposes bellow, comment out when the code is working :)
            //alert(":" + FacNameTextValue + ":");

            //now check the string, and if we are left with nothing, then alert the user that the record will be left blank
            if (FacNameTextValue.length < 1) {
                alert("No matching facilility was found, facility field will be left blank.")
            }







        });

    });
</script>

//下面的代码使jquery下拉列表正常工作,并使用ashx处理程序向其提供结果以填充列表
$(文档).ready(函数(){
$('[id$=txt_Search]')。自动完成('/Facility_Search.ashx');
//监视用户单击更新按钮的时间。
$(“[id$=Button1]”。单击(函数(){
//从文本框中获取所选值
FacNameTextValue=$('[id$=txt_Search]')。val()
//删除前缀(设施名称,仅在:字符后保留字符,这应该是
//只留下设备ID
FacNameTextValue=FacNameTextValue.substring(FacNameTextValue.indexOf(“:”)+2);
//过滤掉除了数字以外的所有东西
FacNameTextValue=FacNameTextValue.replace(/\D/g');
//现在,如果字符串为空,我们需要提醒用户未找到任何设施匹配项,他们需要创建一个新的设施匹配项。
//现在用过滤后的设施ID填充文本框
document.getElementsByName('DetailsViewPiSodeEdit$FacilityIDTextBox')[0]。value=FacNameTextValue;
//警报用于以下调试目的,在代码运行时注释掉:)
//警报(“:”+FacNameTextValue+“:”);
//现在检查字符串,如果没有留下任何内容,则通知用户记录将保留为空
如果(FacNameTextValue.length<1){
警报(“未找到匹配的设施,设施字段将留空。”)
}
});
});

好了。希望这有帮助。我相信这是一个真正的横向方式做这件事。如果您有任何建议/改进,请告诉我

我还不清楚你在问什么。在我读这篇文章的时候,听起来好像你想更新外键(session.FacilityID)。这是打字错误吗?你为什么不直接用下拉列表呢?如果基于用户输入的设施不存在,是否要创建新的设施?Dustin-我希望它按FacName列搜索设施表,获取匹配的ID,并更新插曲表FacilityID列。实际上,我有一个基于用户输入的jquery下拉列表。上一个版本使用了下拉列表,但它带来了数千个结果——太多了,用户无法进行排序。对于任何感兴趣的人,我都把问题放在这里。除了更新FacilityID列中的每一条记录之外,它还能工作。我仍然不清楚您想要什么-在第一个示例中,您在select语句中有一个连接,该语句是插曲.FacilityID=Facilities.ID,而update join语句是插曲.FacilityID=Facilities.FacName。