Неправильный синтаксис рядом с буквой "d".
Я пытаюсь обновить по крайней мере 5 различных таблиц в одном тексте команды SQL, и ошибка, которую я получаю, - это неправильный синтаксис рядом с буквой "d". Ниже приведены мои коды:
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
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(); } } }
Что я уже пробовал:
Я исследовал, как сделать текст команды sql для обновления 2 и более таблиц, и это то, что они дали мне в качестве решения:
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" >
я изо всех сил старался копировать, как он это делал, но, похоже, у меня ничего не получалось...
Kornfeld Eliyahu Peter
Было бы неплохо указать нам на линию...
BasicProgrammer__
Ошибка источника говорит мне об этом:
Строка 64: com.Параметры.AddWithValue ("@IsProcessed", ddlIP.SelectedValue);
Строка 65: com.Параметры.AddWithValue ("@DVO_ID", запрос.QueryString ["ID"].Метод toString());
Строка 66: com.Метод executenonquery();
Строка 67: кон.Закрывать();
Строка 68: Ответ.Перенаправление ("~/Operations/DVO_History.aspx");
Строка 66 выделена красным цветом, что означает, что именно отсюда должна исходить ошибка