'd'附近的语法不正确。 [英] Incorrect syntax near 'd'.

查看:71
本文介绍了'd'附近的语法不正确。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在一个SQL命令文本中更新至少5个不同的表,而我得到的错误是'd'附近的语法不正确。以下是我的代码:



Edi_DVO.aspx

I'm trying to update at least 5 different tables in one SQL Command Text and the error I am getting is Incorrect Syntax near 'd'. Below is my codes:

Edi_DVO.aspx

<%@ Page EnableEventValidation="false" Language="C#" MasterPageFile="~/Administrator/Operations.master" 
    AutoEventWireup="true" CodeFile="Edit_DVO.aspx.cs" Inherits="OperationsDepartment.Operations.Edit_DVO" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
 <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">
                    Edit DVO Details</h1>
            </div>
            <!-- /.col-lg-12 -->
        </div>
        <!-- /.row -->
        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        View User # <asp:Literal ID="ltID" runat="server" />
                    </div>
                    <form role="form" id="form1">
                    <div class="panel-body">
                        <div class="row">
                            <div class="col-lg-6">
                                <div class="form-group">
                                    <label>
                                        Customer Last Name</label>
                                    <asp:TextBox ID="txtLN" runat="server" class="form-control" placeholder="Last Name"
                                        required />
                                </div>
                                <div class="form-group">
                                    <label>
                                        Customer First Name</label>
                                    <asp:TextBox ID="txtFN" runat="server" class="form-control" placeholder="First Name"
                                        required />
                                </div>
                                <div class="form-group">
                                    <label>
                                        Dealer Name</label>
                                    <asp:TextBox ID="txtDN" runat ="server" class="form-control" placeholder="Name"
                                        required />
                                </div>
                                <div class="form-group">
                                    <label>
                                        Quantity</label>
                                    <asp:TextBox ID="txtQ" runat="server" class="form-control" placeholder="Quantity"
                                        required />
                                </div>
                                <div class="form-group">
                                    <label>
                                        Model</label>
                                    <asp:DropDownList ID="ddlMod" runat="server" class="form-control">
                                    </asp:DropDownList>
                                </div>
                               
                                <div class="form-group">
                                    <label>
                                        Quotation Reference No</label>
                                    <asp:TextBox ID="txtQR" runat="server" class="form-control" placeholder="Quotation Reference" required />
                                </div>
                                <div class="form-group">
                                    <label>
                                        Total Amount</label>
                                    <asp:TextBox ID="txtTA" runat="server" class="form-control" placeholder="Total Amount"
                                        required />
                                </div>
                                </br>
                            </div>
                            <!-- /.col-lg-6 (nested) -->
                            <div class="col-lg-6">
                                <div class="form-group">
                                    <label>
                                        Payment Term</label>
                                    <asp:DropDownList ID="ddlPT" runat="server" class="form-control">
                                    </asp:DropDownList>
                                </div>
                                <div class="form-group">
                                    <label>
                                        Target Delivery</label>
                                    <asp:TextBox ID="txtTD" runat="server" class="form-control" placeholder="Target Delivery" required />
                                </div>
                                <div class="form-group">
                                    <label>
                                        Status</label>
                                    <asp:DropDownList ID="ddlStatus" runat="server" Width="200px">
                                        <asp:ListItem Text="Approved" Value="Approved"></asp:ListItem>
                                        <asp:ListItem Text="Pending" Value="Pending"></asp:ListItem>
                                    </asp:DropDownList>
                                </div>
                                <div class="form-group">
                                    <label>
                                        Received</label>
                                    <asp:DropDownList ID="ddlIR" runat="server" class="form-control">
                                        <asp:ListItem Text="Yes" Value="True"></asp:ListItem>
                                        <asp:ListItem Text="No" Value="False"></asp:ListItem>
                                    </asp:DropDownList>
                                </div>
                                <div class="form-group">
                                    <label>
                                        Approved</label>
                                    <asp:DropDownList ID="ddlIA" runat="server" class="form-control">
                                        <asp:ListItem Text="Yes" Value="True"></asp:ListItem>
                                        <asp:ListItem Text="No" Value="False"></asp:ListItem>
                                    </asp:DropDownList>
                                </div>
                                <div class="form-group">
                                    <label>
                                        Evaluated</label>
                                    <asp:DropDownList ID="ddlIE" runat="server" class="form-control">
                                        <asp:ListItem Text="Yes" Value="True"></asp:ListItem>
                                        <asp:ListItem Text="No" Value="False"></asp:ListItem>
                                    </asp:DropDownList>
                                </div>
                                <div class="form-group">
                                    <label>
                                        Processed</label>
                                    <asp:DropDownList ID="ddlIP" runat="server" class="form-control">
                                        <asp:ListItem Text="Yes" Value="True"></asp:ListItem>
                                        <asp:ListItem Text="No" Value="False"></asp:ListItem>
                                    </asp:DropDownList>
                                </div>
                            </div>
                            <!-- /.col-lg-6 (nested) -->
                        </div>
                        <asp:Button ID="btnCancel" runat="server" class="btn btn-default" Text="Cancel" PostBackUrl="~/Operations/DVO_History.aspx"
                            formnovalidate />
                        <asp:Button ID="btnSubmit_Edit" runat="server" class="btn btn-success" Text="Submit Button"
                            OnClick="btnSubmit_Edit_Click" />
                        <!-- /.row (nested) -->
                    </div>
                    </form>
                    <!-- /.panel-body -->
                </div>
                <!-- /.panel -->
            </div>
            <!-- /.col-lg-12 -->
        </div>
        <!-- /.row -->
    </div>
</asp:Content>





Edit_DVO



Edit_DVO

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

namespace OperationsDepartment.Operations
{
    public partial class Edit_DVO : System.Web.UI.Page
    {
        SqlConnection con = new SqlConnection(Helper.GetCon());
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["ID"] != null) // record no selected
            {
                int userID = 0;
                bool validDVO_ID = int.TryParse(Request.QueryString["ID"].ToString(), out userID);

                if (validDVO_ID)
                {
                    if (!IsPostBack)
                    {
                        GetModel();
                        GetPaymentTerm();
                        GetInfo(userID);
                    }
                }
                else
                    Response.Redirect("DVO_History.aspx");
            }
            else
                Response.Redirect("DVO_History.aspx"); //change this to main homepage if meron na
        }
    
        protected void btnSubmit_Edit_Click(object sender, EventArgs e)
        {
            con.Open();
            SqlCommand com = new SqlCommand();
            com.Connection = con;
            com.CommandText = "Update DVO d INNER JOIN Customer c ON d.CustomerID = c.CustomerID INNER JOIN Dealer dt ON d.DealerID = dt.DealerID INNER JOIN " +
                "Product p ON d.ProductID = p.ProductID INNER JOIN PaymentTerm pt ON d.PaymentTermID = pt.PaymentTermID " +
                "SET c.LastName=@LastName, c.FirstName=@FirstName, dt.DealerName=@DealerName, p.Model=@ProductID, pt.Term=@PaymentTermID, " +
                "d.Qty=@Qty, d.QuotationRefNo=@QuotationRefNo, d.TotalAmount=@TotalAmount, d.TargetDelivery=@TargetDelivery, " +
                "d.Status=@Status, d.IsReceived=@IsReceived, d.IsApproved=@IsApproved, d.IsEvaluated=@IsEvaluated, " +
                "d.IsProcessed=@IsProcessed WHERE d.DVO_ID='13'";
            com.Parameters.AddWithValue("@LastName", txtLN.Text);
            com.Parameters.AddWithValue("@FirstName", txtFN.Text);
            com.Parameters.AddWithValue("@DealerName", txtDN.Text);
            com.Parameters.AddWithValue("@Qty", txtQ.Text);
            com.Parameters.AddWithValue("@ProductID", ddlMod.SelectedValue);
            com.Parameters.AddWithValue("@QuotationRefNo", txtQR.Text);
            com.Parameters.AddWithValue("@TotalAmount", txtTA.Text);
            com.Parameters.AddWithValue("@PaymentTermID", ddlPT.SelectedValue);
            com.Parameters.AddWithValue("@TargetDelivery", txtTD.Text);
            com.Parameters.AddWithValue("@Status", ddlStatus.SelectedValue);
            com.Parameters.AddWithValue("@IsReceived", ddlIR.SelectedValue);
            com.Parameters.AddWithValue("@IsApproved", ddlIA.SelectedValue);
            com.Parameters.AddWithValue("@IsEvaluated", ddlIE.SelectedValue);
            com.Parameters.AddWithValue("@IsProcessed", ddlIP.SelectedValue);
            //com.Parameters.AddWithValue("@DVO_ID", Request.QueryString["ID"].ToString());
            com.ExecuteNonQuery();
            con.Close();
            Response.Redirect("~/Operations/DVO_History.aspx");
            
        }
        void GetInfo(int ID)
        {
            con.Open();
            SqlCommand com = new SqlCommand();
            com.Connection = con;
            com.CommandText = "SELECT c.LastName, c.FirstName, dt.DealerName, " +
                "d.Qty, p.Model, d.QuotationRefNo, d.TotalAmount, pt.Term, d.TargetDelivery, d.Status, " +
                "d.IsReceived, d.IsApproved, d.IsEvaluated, d.IsProcessed " +
                "FROM DVO d " +
                "INNER JOIN Dealer dt ON d.DealerID=dt.DealerID " +
                "INNER JOIN Customer c ON d.CustomerID=c.CustomerID " +
                "INNER JOIN Product p ON d.ProductID=p.ProductID " +
                "INNER JOIN PaymentTerm pt ON d.PaymentTermID=pt.PaymentTermID " +
                "Where d.DVO_ID=@ID";
            com.Parameters.AddWithValue("@ID", ID);

            SqlDataReader dr = com.ExecuteReader();
            if (dr.HasRows) //record existing
            {
                while (dr.Read())
                {
                    //ltID.Text = dr["DVO_ID"].ToString();
                    ddlMod.SelectedValue = dr["Model"].ToString();
                    ddlStatus.SelectedValue = dr["Status"].ToString();
                    //ddlPT.SelectedValue = dr["PaymentTerm"].ToString();
                    ddlIR.SelectedValue = dr["IsReceived"].ToString();
                    ddlIA.SelectedValue = dr["IsApproved"].ToString();
                    ddlIE.SelectedValue = dr["IsEvaluated"].ToString();
                    ddlIP.SelectedValue = dr["IsProcessed"].ToString();
                    txtFN.Text = dr["FirstName"].ToString();
                    txtLN.Text = dr["LastName"].ToString();
                    txtDN.Text = dr["DealerName"].ToString();
                    txtQ.Text = dr["Qty"].ToString();

                    txtQR.Text = dr["QuotationRefNo"].ToString();
                    txtTA.Text = dr["TotalAmount"].ToString();
                    txtTD.Text = dr["TargetDelivery"].ToString();


                }
                con.Close();
            }
            else // not existing
            {
                con.Close();
                Response.Redirect("DVO_History.aspx");

            }
        }


        void GetModel()
        {
            con.Open();
            SqlCommand com = new SqlCommand();
            com.Connection = con;
            com.CommandText = "SELECT ProductID, Model FROM Product";
            SqlDataReader dr = com.ExecuteReader();
            ddlMod.DataSource = dr;
            ddlMod.DataTextField = "Model";
            ddlMod.DataValueField = "ProductID";
            ddlMod.DataBind();
            con.Close();

        }


        void GetPaymentTerm()
        {
            con.Open();
            SqlCommand com = new SqlCommand();
            com.Connection = con;
            com.CommandText = "SELECT PaymentTermID, Term FROM PaymentTerm";
            SqlDataReader dr = com.ExecuteReader();
            ddlPT.DataSource = dr;
            ddlPT.DataTextField = "Term";
            ddlPT.DataValueField = "PaymentTermID";
            ddlPT.DataBind();
            con.Close();

        }




    }
}





我尝试了什么:



我研究了如何更新2和sql命令文本更多的表格,这是他们给我的解决方案:



What I have tried:

I researched on how to do a sql command text for updating 2 and more tables and this is what they gave me as a solution:

UpdateCommand=" UPDATE 
                    individual i
                INNER JOIN 
                    address a 
                        ON i.IndividualID = a.IndividualID 
                SET 
                    i.FarmName = @FarmName, 
                    i.FirstName = @FirstName,  
                    i.MiddleName = @MiddleName, 
                    a.Address1 = @Address1, 
                    a.City = @City 
                WHERE 
                    i.IndividualID=@IndividualID" >



i尽力复制他是怎么做到的,但似乎对我不起作用......


i tried my best to copy how he did it but it doesn't seem to work for me...

推荐答案

我刚发现它...

I just spotted it...
Update DVO d INNER JOIN



您不能在更新中使用别名...或者至少不能使用这样的...

Alias只能在FROM或JOIN中设置SQL ...

所以在更新中你必须这样做:


You can not use alias in update... or at least no like this...
Alias can be set in SQL only at FROM or JOIN...
So in UPDATE you have to do it like this:

Update DVO SET ... FROM DVO d INNER JOIN


这篇关于'd'附近的语法不正确。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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