我有以下問題:我有2個表:顯示數據時,Visual Studio 2010(數據綁定?)
1)表1:客戶(CUSTOMER_ID(主鍵),姓名,電話,地址,郵件) 2)表2:車輛(REG_STEVILKA(主鍵),CUSTOMER_ID,牌子,型號,LETO_IZDELAVE,PROSTORNINA_MOTORJA,MOC_MOTORJA,TIP_MOTORJA,VIN_STEVILKA)
「客戶」 的每個成員可以有0:N 「車輛」的成員,而「車」的每個成員從「客戶」有且只有一個成員。
現在,我有DetailsView控件(DetailsView2是實際的名稱和代碼),從「車」的某些成員顯示所有列。現在 - 我想對與「名+姓」替換列「CUSTOMER_ID」。這些做到這一點我必須以某種方式連接這兩個表或東西...我真的不知道該怎麼做。誰能幫助?謝謝!
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Vozila.aspx.cs" Inherits="CernaticJurij_Default2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<h3>ISKANJE PODATKOV VOZIL</h3>
<p>Za prikaz podatkov vozila lahko neposredno vnesete registrsko številko vozila,
lahko pa najprej poiščete stranko ter izberete željeno vozilo.</p>
<br />
Registrska številka vozila oziroma ime ali priimek stranke:<br />
<br />
<asp:TextBox ID="okno_iskanje_strank" runat="server"></asp:TextBox>
<asp:Button ID="iskanje_stranke" runat="server" Height="25px"
style="margin-top: 0px" Text="Iskanje" Width="70px" />
<br />
<br />
<br />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="ID_STRANKE" DataSourceID="SQL_STRANKE" Height="16px"
Width="881px" AllowPaging="True" CellPadding="4" ForeColor="#333333"
GridLines="None">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:CommandField
ShowSelectButton="True" SelectText="Izberi" />
<asp:BoundField DataField="ID_STRANKE" HeaderText="ID STRANKE" ReadOnly="True"
SortExpression="ID_STRANKE" />
<asp:BoundField DataField="IME" HeaderText="IME" SortExpression="IME" />
<asp:BoundField DataField="PRIIMEK" HeaderText="PRIIMEK"
SortExpression="PRIIMEK" />
<asp:BoundField DataField="TELEFON" HeaderText="TELEFON"
SortExpression="TELEFON" />
<asp:BoundField DataField="NASLOV" HeaderText="NASLOV"
SortExpression="NASLOV" />
<asp:BoundField DataField="POSTA" HeaderText="POŠTA" SortExpression="POSTA" />
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
<asp:SqlDataSource ID="SQL_STRANKE" runat="server"
ConnectionString="<%$ ConnectionStrings:Stranke %>"
SelectCommand="SELECT * FROM [STRANKA] WHERE ([PRIIMEK] LIKE @PRIIMEK+'%') OR ([IME] LIKE @PRIIMEK+'%')"
DeleteCommand="DELETE FROM [STRANKA] WHERE [ID_STRANKE] = @ID_STRANKE"
InsertCommand="INSERT INTO [STRANKA] ([ID_STRANKE], [IME], [PRIIMEK], [TELEFON], [NASLOV], [POSTA]) VALUES (@ID_STRANKE, @IME, @PRIIMEK, @TELEFON, @NASLOV, @POSTA)"
UpdateCommand="UPDATE [STRANKA] SET [IME] = @IME, [PRIIMEK] = @PRIIMEK, [TELEFON] = @TELEFON, [NASLOV] = @NASLOV, [POSTA] = @POSTA WHERE [ID_STRANKE] = @ID_STRANKE">
<DeleteParameters>
<asp:Parameter Name="ID_STRANKE" Type="String" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="ID_STRANKE" Type="String" />
<asp:Parameter Name="IME" Type="String" />
<asp:Parameter Name="PRIIMEK" Type="String" />
<asp:Parameter Name="TELEFON" Type="String" />
<asp:Parameter Name="NASLOV" Type="String" />
<asp:Parameter Name="POSTA" Type="String" />
</InsertParameters>
<SelectParameters>
<asp:ControlParameter ControlID="okno_iskanje_strank" Name="PRIIMEK"
PropertyName="Text" Type="String" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="IME" Type="String" />
<asp:Parameter Name="PRIIMEK" Type="String" />
<asp:Parameter Name="TELEFON" Type="String" />
<asp:Parameter Name="NASLOV" Type="String" />
<asp:Parameter Name="POSTA" Type="String" />
<asp:Parameter Name="ID_STRANKE" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:DetailsView ID="DetailsView2" runat="server" AutoGenerateRows="False"
CellPadding="4" DataKeyNames="REG_STEVILKA" DataSourceID="SqlDataSource4"
ForeColor="#333333" GridLines="None" Height="50px" Width="300px">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
<EditRowStyle BackColor="#999999" />
<FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" />
<Fields>
<asp:BoundField DataField="REG_STEVILKA" HeaderText="REGISTRSKA ŠTEVILKA"
ReadOnly="True" SortExpression="REG_STEVILKA" />
<asp:BoundField DataField="ID_STRANKE" HeaderText="ID_STRANKE"
SortExpression="ID_STRANKE" />
<asp:BoundField DataField="ZNAMKA" HeaderText="ZNAMKA"
SortExpression="ZNAMKA" />
<asp:BoundField DataField="MODEL" HeaderText="MODEL" SortExpression="MODEL" />
<asp:BoundField DataField="LETO_IZDELAVE" HeaderText="LETO IZDELAVE"
SortExpression="LETO_IZDELAVE" />
<asp:BoundField DataField="PROSTORNINA_MOTORJA"
HeaderText="PROSTORNINA MOTORJA" SortExpression="PROSTORNINA_MOTORJA" />
<asp:BoundField DataField="MOC_MOTORJA" HeaderText="MOČ MOTORJA"
SortExpression="MOC_MOTORJA" />
<asp:BoundField DataField="TIP_MOTORJA" HeaderText="TIP MOTORJA"
SortExpression="TIP_MOTORJA" />
<asp:BoundField DataField="VIN_STEVILKA" HeaderText="VIN ŠTEVILKA"
SortExpression="VIN_STEVILKA" />
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True"
CancelText="Prekliči" DeleteText="Izbriši" EditText="Uredi"
UpdateText="Shrani" />
</Fields>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
</asp:DetailsView>
<br />
<asp:GridView ID="GridView2" runat="server" AllowPaging="True"
AutoGenerateColumns="False" DataKeyNames="REG_STEVILKA"
DataSourceID="SqlDataSource2" CellPadding="4" ForeColor="#333333"
GridLines="None" Width="400px">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:CommandField ShowDeleteButton="False" ShowEditButton="False"
ShowSelectButton="True" CancelText="Prekliči" DeleteText="Izbriši"
EditText="Uredi" InsertText="Shrani" NewText="Dodaj " SelectText="Izberi"
UpdateText="Shrani" />
<asp:BoundField DataField="REG_STEVILKA" HeaderText="REGISTRSKA ŠTEVILKA"
ReadOnly="True" SortExpression="REG_STEVILKA" />
<asp:BoundField DataField="ZNAMKA" HeaderText="ZNAMKA"
SortExpression="ZNAMKA" />
<asp:BoundField DataField="MODEL" HeaderText="MODEL" SortExpression="MODEL" />
</Columns>
<EditRowStyle BackColor="#999999" />
<EmptyDataTemplate>
</EmptyDataTemplate>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:Stranke %>"
DeleteCommand="DELETE FROM [VOZILO] WHERE [REG_STEVILKA] = @REG_STEVILKA"
InsertCommand="INSERT INTO [VOZILO] ([REG_STEVILKA], [ZNAMKA], [MODEL]) VALUES (@REG_STEVILKA, @ZNAMKA, @MODEL)"
SelectCommand="SELECT [REG_STEVILKA], [ZNAMKA], [MODEL] FROM [VOZILO] WHERE ([ID_STRANKE] = @ID_STRANKE)"
UpdateCommand="UPDATE [VOZILO] SET [ZNAMKA] = @ZNAMKA, [MODEL] = @MODEL WHERE [REG_STEVILKA] = @REG_STEVILKA">
<DeleteParameters>
<asp:Parameter Name="REG_STEVILKA" Type="String" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="REG_STEVILKA" Type="String" />
<asp:Parameter Name="ZNAMKA" Type="String" />
<asp:Parameter Name="MODEL" Type="String" />
</InsertParameters>
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="ID_STRANKE"
PropertyName="SelectedValue" Type="String" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="ZNAMKA" Type="String" />
<asp:Parameter Name="MODEL" Type="String" />
<asp:Parameter Name="REG_STEVILKA" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
<br />
<br />
<br />
<asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True"
AutoGenerateRows="False" CellPadding="4" DataKeyNames="REG_STEVILKA"
DataSourceID="SqlDataSource3" ForeColor="#333333" GridLines="None"
Height="50px" Width="300px">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
<EditRowStyle BackColor="#999999" />
<EmptyDataTemplate>
<asp:LinkButton ID="NovoPrazno" runat="server" CausesValidation="False"
CommandName="New" Text="Vnos novega vozila" />
</EmptyDataTemplate>
<FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" />
<Fields>
<asp:BoundField DataField="REG_STEVILKA" HeaderText="REGISTRSKA ŠTEVILKA"
ReadOnly="True" SortExpression="REG_STEVILKA" />
<asp:BoundField DataField="ZNAMKA" HeaderText="ZNAMKA"
SortExpression="ZNAMKA" />
<asp:BoundField DataField="MODEL"
HeaderText="MODEL" SortExpression="MODEL" />
<asp:BoundField DataField="LETO_IZDELAVE" HeaderText="LETO IZDELAVE"
SortExpression="LETO_IZDELAVE" />
<asp:BoundField DataField="PROSTORNINA_MOTORJA" HeaderText="PROSTORNINA MOTORJA"
SortExpression="PROSTORNINA_MOTORJA" />
<asp:BoundField DataField="MOC_MOTORJA" HeaderText="MOČ MOTORJA"
SortExpression="MOC_MOTORJA" />
<asp:BoundField DataField="TIP_MOTORJA" HeaderText="TIP MOTORJA"
SortExpression="TIP_MOTORJA" />
<asp:BoundField DataField="VIN_STEVILKA" HeaderText="VIN ŠTEVILKA"
SortExpression="VIN_STEVILKA" />
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True"
ShowInsertButton="True" CancelText="Prekliči" DeleteText="Izbriši"
EditText="Uredi" InsertText="Shrani" NewText="Dodaj novo vozilo"
UpdateText="Shrani" />
</Fields>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:Stranke %>"
SelectCommand="SELECT * FROM [VOZILO] WHERE (([REG_STEVILKA] = @REG_STEVILKA))"
DeleteCommand="DELETE FROM [VOZILO] WHERE [REG_STEVILKA] = @REG_STEVILKA"
InsertCommand="INSERT INTO [VOZILO] ([REG_STEVILKA], [ID_STRANKE], [ZNAMKA], [MODEL], [LETO_IZDELAVE], [PROSTORNINA_MOTORJA], [MOC_MOTORJA], [TIP_MOTORJA], [VIN_STEVILKA]) VALUES (@REG_STEVILKA, @ID_STRANKE, @ZNAMKA, @MODEL, @LETO_IZDELAVE, @PROSTORNINA_MOTORJA, @MOC_MOTORJA, @TIP_MOTORJA, @VIN_STEVILKA)"
UpdateCommand="UPDATE [VOZILO] SET [ZNAMKA] = @ZNAMKA, [MODEL] = @MODEL, [LETO_IZDELAVE] = @LETO_IZDELAVE, [PROSTORNINA_MOTORJA] = @PROSTORNINA_MOTORJA, [MOC_MOTORJA] = @MOC_MOTORJA, [TIP_MOTORJA] = @TIP_MOTORJA, [VIN_STEVILKA] = @VIN_STEVILKA WHERE [REG_STEVILKA] = @REG_STEVILKA">
<DeleteParameters>
<asp:Parameter Name="REG_STEVILKA" Type="String" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="REG_STEVILKA" Type="String" />
<asp:ControlParameter ControlID="GridView1" Name="ID_STRANKE"
PropertyName="SelectedValue" Type="String" />
<asp:Parameter Name="ZNAMKA" Type="String" />
<asp:Parameter Name="MODEL" Type="String" />
<asp:Parameter Name="LETO_IZDELAVE" Type="String" />
<asp:Parameter Name="PROSTORNINA_MOTORJA" Type="String" />
<asp:Parameter Name="MOC_MOTORJA" Type="String" />
<asp:Parameter Name="TIP_MOTORJA" Type="String" />
<asp:Parameter Name="VIN_STEVILKA" Type="String" />
</InsertParameters>
<SelectParameters>
<asp:ControlParameter ControlID="GridView2" Name="REG_STEVILKA"
PropertyName="SelectedValue" Type="String" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="ZNAMKA" Type="String" />
<asp:Parameter Name="MODEL" Type="String" />
<asp:Parameter Name="LETO_IZDELAVE" Type="String" />
<asp:Parameter Name="PROSTORNINA_MOTORJA" Type="String" />
<asp:Parameter Name="MOC_MOTORJA" Type="String" />
<asp:Parameter Name="TIP_MOTORJA" Type="String" />
<asp:Parameter Name="VIN_STEVILKA" Type="String" />
<asp:Parameter Name="REG_STEVILKA" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
<br />
<asp:SqlDataSource ID="SqlDataSource4" runat="server"
ConnectionString="<%$ ConnectionStrings:Stranke %>"
DeleteCommand="DELETE FROM [VOZILO] WHERE [REG_STEVILKA] = @REG_STEVILKA"
InsertCommand="INSERT INTO [VOZILO] ([REG_STEVILKA], [ID_STRANKE], [ZNAMKA], [MODEL], [LETO_IZDELAVE], [PROSTORNINA_MOTORJA], [MOC_MOTORJA], [TIP_MOTORJA], [VIN_STEVILKA]) VALUES (@REG_STEVILKA, @ID_STRANKE, @ZNAMKA, @MODEL, @LETO_IZDELAVE, @PROSTORNINA_MOTORJA, @MOC_MOTORJA, @TIP_MOTORJA, @VIN_STEVILKA)"
SelectCommand="SELECT * FROM [VOZILO] WHERE ([REG_STEVILKA] = @REG_STEVILKA)"
UpdateCommand="UPDATE [VOZILO] SET [ID_STRANKE] = @ID_STRANKE, [ZNAMKA] = @ZNAMKA, [MODEL] = @MODEL, [LETO_IZDELAVE] = @LETO_IZDELAVE, [PROSTORNINA_MOTORJA] = @PROSTORNINA_MOTORJA, [MOC_MOTORJA] = @MOC_MOTORJA, [TIP_MOTORJA] = @TIP_MOTORJA, [VIN_STEVILKA] = @VIN_STEVILKA WHERE [REG_STEVILKA] = @REG_STEVILKA">
<DeleteParameters>
<asp:Parameter Name="REG_STEVILKA" Type="String" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="REG_STEVILKA" Type="String" />
<asp:Parameter Name="ID_STRANKE" Type="String" />
<asp:Parameter Name="ZNAMKA" Type="String" />
<asp:Parameter Name="MODEL" Type="String" />
<asp:Parameter Name="LETO_IZDELAVE" Type="String" />
<asp:Parameter Name="PROSTORNINA_MOTORJA" Type="String" />
<asp:Parameter Name="MOC_MOTORJA" Type="String" />
<asp:Parameter Name="TIP_MOTORJA" Type="String" />
<asp:Parameter Name="VIN_STEVILKA" Type="String" />
</InsertParameters>
<SelectParameters>
<asp:ControlParameter ControlID="okno_iskanje_strank" Name="REG_STEVILKA"
PropertyName="Text" Type="String" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="ID_STRANKE" Type="String" />
<asp:Parameter Name="ZNAMKA" Type="String" />
<asp:Parameter Name="MODEL" Type="String" />
<asp:Parameter Name="LETO_IZDELAVE" Type="String" />
<asp:Parameter Name="PROSTORNINA_MOTORJA" Type="String" />
<asp:Parameter Name="MOC_MOTORJA" Type="String" />
<asp:Parameter Name="TIP_MOTORJA" Type="String" />
<asp:Parameter Name="VIN_STEVILKA" Type="String" />
<asp:Parameter Name="REG_STEVILKA" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
</asp:Content>
謝謝,但什麼是錯的這個SQL語句: 的SelectCommand =「SELECT *姓名+‘’+姓AS性複合物[汽車]內加入[S]上VOZILO.ID_STRANKE = STRANKE.ID_STRANKE WHERE([REG_STEVILKA] = @REG_STEVILKA) 「 我得到」 不正確附近的酒店名稱語法」。 – jurij
此外,我得到這個錯誤:異常詳細信息:System.Web.HttpException:數據綁定:「System.Data.DataRowView」不包含與名稱的屬性「STRANKE_ID」。 – jurij
錯誤在我的部分一對夫婦。你最好現在的工作。 –