我想寫一個更新命令,使用SqlDataSource
連接兩個表。我有它與1表工作,但是當我把我的INNER JOIN
語法在我得到一個錯誤。它說: 「我語法是錯誤的。檢查MySQL手冊的語法是否正確」語法錯誤使用INNER JOIN和SqlDataSource與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 [email protected]">
<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>
UPDATE
我有它現在與2張桌子一起工作。但它會更新表中的每個人。例如:我正在嘗試更新1個人,並將第一個名稱更改爲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>
只是一個提示。當你更新你的問題時,不要抹掉原來的代碼或問題。當人們現在來看問題時,他們會問爲什麼@jadarnel的回答幾乎與您所擁有的相同。 – 2012-02-16 22:15:10
更新了您的問題(恢復原始版本)。 – 2012-02-16 22:19:07