我想从sql server中将 10 last rows 插入我的gridview并在我的页面中显示它们。 这是我的问题:
SELECT Cause.Cause_name
,City.City_name
,InjuryScenario.InjuryScenario_id
,InjuryScenario.InjuryScenario_name
,InjuryScenario.InjuryDay
,InjuryScenario.InjuryMonth
,InjuryScenario.InjuryYear
,Place.Place_name
FROM InjuryScenario
INNER JOIN Cause
ON InjuryScenario.Cause_id = Cause.Cause_id
INNER JOIN PlaceDet
ON InjuryScenario.InjuryScenario_id = PlaceDet.InjuryScenario_id
INNER JOIN City
ON PlaceDet.City_id = City.City_id
INNER JOIN Place
ON InjuryScenario.Place_id = Place.Place_id)
这是我在aspx中的代码:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="InjuryScenario_id" DataSourceID="SqlDataSource30" ShowHeaderWhenEmpty="True">
<Columns>
<asp:BoundField DataField="InjuryScenario_id" HeaderText="InjuryScenario_id" ReadOnly="True" SortExpression="InjuryScenario_id" />
<asp:BoundField DataField="InjuryScenario_name" HeaderText="InjuryScenario_name" SortExpression="InjuryScenario_name" />
<asp:BoundField DataField="Cause_name" HeaderText="Cause_name" SortExpression="Cause_name" />
<asp:BoundField DataField="City_name" HeaderText="City_name" SortExpression="City_name" />
<asp:BoundField DataField="Place_name" HeaderText="Place_name" SortExpression="Place_name" />
<asp:BoundField DataField="InjuryDay" HeaderText="InjuryDay" SortExpression="InjuryDay" Visible="False"/>
<asp:BoundField DataField="InjuryMonth" HeaderText="InjuryMonth" SortExpression="InjuryMonth" Visible="False"/>
<asp:BoundField DataField="InjuryYear" HeaderText="InjuryYear" SortExpression="InjuryYear" Visible="False"/>
<asp:TemplateField HeaderText="Date">
<ItemTemplate>
<asp:Label runat="server"><%#(int)Eval("InjuryDay")+"/"+ Eval("InjuryMonth")+"/"+ Eval("InjuryYear") %></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
这里是插入代码:
DBManager db = new DBManager();
db.Insert("InjuryScenario", "InjuryScenario_id,"+"Cause_id," + "CauseType_id," +
"CauseChar_id," + "Place_id," + "PlaceType_id," + "InjuryYear," + "InjuryMonth," +
"InjuryDay," + "InjuryDate_id," + "InjuryInSchool," + "InjuryDesc," + "AlmostInjury,"
+ "InjuryComments," + "ProductInjury","'"+ num_id + "'" + Cause_nameDD.SelectedValue +
"','" + CauseTypeDD.DataValueField + "','" + CauseCharDD.SelectedValue + "','" +
PlaceDD.SelectedValue + "','" + PlaceTypeDD.SelectedValue + "','" +
YearDD.SelectedValue + "','" + MonthDD.SelectedValue + "','" + DayDD.SelectedValue +
"','" + InjuryDateDD.SelectedValue + "','" + InjuryInSchoolCBL.SelectedValue + "','" +
InjuryDescTB.Text + "','" + AlmostInjuryTB.Text + "','" + InjuryCommentTB.Text + "','"
+ ProductInjuryCBL.Text + "'");
答案 0 :(得分:0)
我们需要查看insert语句,并知道如何唯一地识别每个案例以提供帮助。 我通常做这样的事情,每个新案例都有一个唯一的ID作为自动增量。此ID用于在所有表中引用参照完整性。
然后为了退出最后十个案例,我只想创建一个像
这样的语句选择...... 从... ID IN( 从CASE_IDS中选择CASE_IDS.ID ORDER BY CASE_IDS.ID DESC WHERE ROWNUM&lt; 11 )
希望这有帮助。