我正在尝试编写一个更新命令,该命令使用SqlDataSource
. 我让它与 1 个表一起工作,但是当我把我的INNER JOIN
语法放进去时,我得到了一个错误。它说“我的语法错误。检查 MySql 手册以获取正确的语法”
这是我的 ASPX 页面中的代码:
<asp:SqlDataSource ID="AdminSalesmanDetailDS" runat="server"
ConnectionString="<%$ ConnectionStrings:intelliairConnectionString %>"
ProviderName="<%$ ConnectionStrings:intelliairConnectionString.ProviderName %>"
SelectCommand="individual_AddressByIndividualID"
SelectCommandType="StoredProcedure"
UpdateCommand="UPDATE individual SET
FarmName = @FarmName,
FirstName = @FirstName,
MiddleName = @MiddleName,
Address1 = @Address1,
City = @City
INNER JOIN address a ON i.IndividualID = a.IndividualID,
WHERE IndividualID=@IndividualID">
<SelectParameters>
<asp:ControlParameter ControlID="gvSalesman" Name="oIndividualID"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:ControlParameter Name="FarmName" ControlId="fvAdminSalesmanDetail$CompanyTextBox" PropertyName="Text"/>
<asp:ControlParameter Name="FirstName" ControlId="fvAdminSalesmanDetail$FirstNameTextBox" PropertyName="Text"/>
<asp:ControlParameter Name="MiddleName" ControlId="fvAdminSalesmanDetail$MiddleNameTextBox" PropertyName="Text"/>
<asp:ControlParameter Name="Address1" ControlId="fvAdminSalesmanDetail$Address1TextBox" PropertyName="Text"/>
<asp:ControlParameter Name="City" ControlId="fvAdminSalesmanDetail$cityTextBox" PropertyName="Text"/>
</UpdateParameters>
</asp:SqlDataSource>
更新
我现在可以使用 2 张桌子。但是,它会更新表中的每个个体。例如:我正在尝试更新 1 个人并将名字更改为 Mark。当我单击 update 时,它会将 Database First Name 中的每个人都更改为 Mark。
这是我的 ASPX 页面中的新代码:
<asp:SqlDataSource ID="AdminSalesmanDetailDS" runat="server"
ConnectionString="<%$ ConnectionStrings:intelliairConnectionString %>"
ProviderName="<%$ ConnectionStrings:intelliairConnectionString.ProviderName %>"
SelectCommand="individual_AddressByIndividualID"
SelectCommandType="StoredProcedure"
UpdateCommand="UPDATE individual i
inner join address a
on a.individualID = i.individualID
set
i.FarmName = @FarmName,
i.FirstName = @FirstName,
i.LastName = @LastName,
i.MiddleName = @MiddleName,
i.Phone = @Phone,
i.PhoneExtention = @PhoneExtention,
i.MobilPhone = @MobilPhone,
i.Fax = @Fax,
i.Email = @Email,
a.Address1 = @Address1,
a.Address2 = @Address2,
a.City = @City,
a.State = @State,
a.Zip = @Zip,
a.Country = @Country
where
i.IndividualID = i.IndividualID">
<SelectParameters>
<asp:ControlParameter ControlID="gvSalesman" Name="oIndividualID"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:ControlParameter Name="FarmName" ControlId="fvAdminSalesmanDetail$CompanyTextBox" PropertyName="Text"/>
<asp:ControlParameter Name="FirstName" ControlId="fvAdminSalesmanDetail$FirstNameTextBox" PropertyName="Text"/>
<asp:ControlParameter Name="MiddleName" ControlId="fvAdminSalesmanDetail$MiddleNameTextBox" PropertyName="Text"/>
<asp:ControlParameter Name="Address1" ControlId="fvAdminSalesmanDetail$Address1TextBox" PropertyName="Text"/>
<asp:ControlParameter Name="City" ControlId="fvAdminSalesmanDetail$cityTextBox" PropertyName="Text"/>
</UpdateParameters>
</asp:SqlDataSource>