我最近在保存临时数据时使用数据表。
我必须先使用下拉列表和添加按钮将临时数据保存到数据表中。单击提交按钮后,数据将仅保存在数据库中。
如何使用下拉列表中的选定值和添加按钮将第一个临时数据保存到数据表中,然后使用提交按钮将数据保存到数据库?
<table width="100%" border="0" cellspacing="8" cellpadding="0">
<tr>
<td>
<label>
Fishing Ground
</label>
<br />
<asp:DropDownList ID="ddllevelRef" runat="server">
<asp:ListItem Selected="True" Value="0">-- Select One --</asp:ListItem>
<asp:ListItem Value="Albay Gulf"></asp:ListItem>
<asp:ListItem Value="Asid Gulf"></asp:ListItem>
<asp:ListItem Value="Babuyan Channel"></asp:ListItem>
<asp:ListItem Value="Bacuit Bay"></asp:ListItem>
<asp:ListItem Value="Batangas Coast"></asp:ListItem>
<asp:ListItem Value="Bohol Strait"></asp:ListItem>
<asp:ListItem Value="Camotes Sea"></asp:ListItem>
<asp:ListItem Value="Capiz Coast"></asp:ListItem>
<asp:ListItem Value="Carigara Bay"></asp:ListItem>
<asp:ListItem Value="Coron Bay"></asp:ListItem>
<asp:ListItem Value="Davao Gulf"></asp:ListItem>
<asp:ListItem Value="Dumaran Channel"></asp:ListItem>
<asp:ListItem Value="Green Islands Bay"></asp:ListItem>
<asp:ListItem Value="Guimaras Strait"></asp:ListItem>
<asp:ListItem Value="Honda Bay"></asp:ListItem>
<asp:ListItem Value="Island Bay"></asp:ListItem>
<asp:ListItem Value="Ilocos Coast"></asp:ListItem>
<asp:ListItem Value="Lagonoy Golf"></asp:ListItem>
<asp:ListItem Value="Lamon Bay"></asp:ListItem>
<asp:ListItem Value="Leyte Gulf"></asp:ListItem>
<asp:ListItem Value="Lingayen Gulf"></asp:ListItem>
<asp:ListItem Value="Malampaya Sound"></asp:ListItem>
<asp:ListItem Value="Manila Bay"></asp:ListItem>
<asp:ListItem Value="Maqueda Bay"></asp:ListItem>
<asp:ListItem Value="Ragay Gulf"></asp:ListItem>
<asp:ListItem Value="San Miguel Bay"></asp:ListItem>
<asp:ListItem Value="Samar Sea"></asp:ListItem>
<asp:ListItem Value="Sibuguey Bay"></asp:ListItem>
<asp:ListItem Value="Sibuyan sea"></asp:ListItem>
<asp:ListItem Value="Sogod Bay"></asp:ListItem>
<asp:ListItem Value="Sulu sea"></asp:ListItem>
<asp:ListItem Value="Tañon Strait"></asp:ListItem>
<asp:ListItem Value="Tayabas Bay"></asp:ListItem>
<asp:ListItem Value="Taytay Bay"></asp:ListItem>
<asp:ListItem Value="Tawi-Tawi Bay"></asp:ListItem>
<asp:ListItem Value="Visayan Sea"></asp:ListItem>
<asp:ListItem Value="Moro Gulf"></asp:ListItem>
<asp:ListItem Value="Palawan waters"></asp:ListItem>
<asp:ListItem Value="Mindanao sea"></asp:ListItem>
<asp:ListItem Value="Benham Rise"></asp:ListItem>
<asp:ListItem Value="Cuyo Pass"></asp:ListItem>
<asp:ListItem Value="High Seas Pocket 1"></asp:ListItem>
</asp:DropDownList>
</td>
<td width="40">
<asp:Button ID="btnAdd" runat="server" OnClientClick="return Validation()" OnClick="lnkSaveReference_Click"
Text="Add" />
</td>
<td>
<asp:Button ID="btnCancel" runat="server" OnClick="lnkCancelReference_Click" Text="Cancel" />
</td>
</tr>
</table>
<hr />
<table>
<tr>
<td>
<asp:GridView ID="gvReference" runat="server" OnRowDeleting="rowDelete" HorizontalAlign="Left" PagerSettings-Visible="true"
CellPadding="4" Width="645px">
</asp:GridView>
</td>
</tr>
<tr>
<td>
<asp:Button ID="save" runat="server" Text="Save" /></td>
</tr>
</table>
Protected Sub lnkSaveReference_Click(ByVal sender As Object, ByVal e As EventArgs)
If (Not (ViewState("CurrentDataReference")) Is Nothing) Then
Dim dt As DataTable = CType(ViewState("CurrentDataReference"), DataTable)
Dim count As Integer = dt.Rows.Count
BindGridReference(count)
ddllevelRef.SelectedValue = "0"
Else
BindGridReference(1)
ddllevelRef.SelectedValue = "0"
End If
End Sub
Private Sub BindGridReference(ByVal rowcount As Integer)
Dim Dt As DataTable = New DataTable
Dim dr As DataRow
Dt.Columns.Add(New System.Data.DataColumn("Fishing Ground", GetType(String)))
If (Not (ViewState("CurrentDataReference")) Is Nothing) Then
Dim i As Integer = 0
Do While (i _
< (rowcount + 1))
Dt = CType(ViewState("CurrentDataReference"), DataTable)
If (Dt.Rows.Count > 0) Then
dr = Dt.NewRow
dr(0) = Dt.Rows(0)(0).ToString
End If
i = (i + 1)
Loop
dr = Dt.NewRow
dr(0) = ddllevelRef.SelectedItem.Text
Dt.Rows.Add(dr)
Else
dr = Dt.NewRow
dr(0) = ddllevelRef.SelectedItem.Text
Dt.Rows.Add(dr)
End If
If (Not (ViewState("CurrentDataReference")) Is Nothing) Then
gvReference.DataSource = CType(ViewState("CurrentDataReference"), DataTable)
gvReference.DataBind()
gvReference.Focus()
Else
gvReference.DataSource = Dt
gvReference.DataBind()
gvReference.Focus()
End If
ViewState("CurrentDataReference") = Dt
End Sub
Protected Sub lnkCancelReference_Click(ByVal sender As Object, ByVal e As EventArgs)
ddllevelRef.SelectedValue = "0"
gvReference.DataSource = Nothing
gvReference.DataBind()
End Sub
- 我必须使用保存按钮将所有添加的列表保存在gridview上。
答案 0 :(得分:0)
第一个可以使用INSERT INTO
查询
第二个:
SELECT * INTO Master_table FROM temp_table;
其中temp_table
:是临时表
注意: