如何从文本框&中存储多个值下拉到数据库 [英] how to store multiple values from textbox & dropdown to database
本文介绍了如何从文本框&中存储多个值下拉到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
请帮助我.我有一个表格,允许用户在要添加数据的情况下添加新行(多个文本框和其中的下拉列表).
现在,我不知道如何从文本框&下拉到数据库?它存储为1行还是多行?如果我想在将来找回值怎么办?哪个是最好的?
hi all,
please help me on this.i have a form which let user to add new row (multiple textbox and dropdown in it) if they want to add data.
right now, i dont know how to store multiple values from textbox & dropdown to database? is it store into 1 row or multiple rows? how about if i want to retrieve values back in future?which one is best?
<SCRIPT language="javascript">
function addRow(data) {
var table = document.getElementById(data);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var colCount = table.rows[0].cells.length;
for (var i = 0; i < colCount; i++) {
var newcell = row.insertCell(i);
newcell.innerHTML = table.rows[0].cells[i].innerHTML;
//alert(newcell.childNodes);
switch (newcell.childNodes[0].type) {
case "text":
newcell.childNodes[0].value = "";
break;
case "checkbox":
newcell.childNodes[0].checked = false;
break;
case "select-one":
newcell.childNodes[0].selectedIndex = 0;
break;
}
}
}
</SCRIPT>
<table style="width: 100%;"><tr><td><h3 style="text-decoration: underline">Sebab Hantar</h3></td></tr></table>
<table style="width: 100%;" border="1" >
<tr>
<td style="width: 100px">Stokereta</td>
<td style="width: 80px">Jenis Roda</td>
<td style="width: 100px">No Siri</td>
<td style="width: 80px">Saiz Roda (mm)</td>
<td style="width: 50px">Flange (mm)</td>
<td style="width: 50px">Hollow (mm)</td>
<td style="width: 100px">Tindakan</td>
<td style="width: 100px">Skidded</td>
<td style="width: 350px">Catatan</td>
</tr>
</table>
<table style="width: 100%;" id="data" border="1" >
<tr>
<td >
<asp:TextBox ID="stokereta" runat="server" Width="100" BorderStyle="None" ></asp:TextBox>
</td>
<td>
<asp:DropDownList ID="ddl_jenisroda" runat="server" Width="80" >
</asp:DropDownList>
</td>
<td>
<asp:TextBox ID="nosiri" runat="server" Width="100" BorderStyle="None" ></asp:TextBox>
</td>
<td>
<asp:TextBox ID="saizroda" runat="server" Width="80" BorderStyle="None" ></asp:TextBox>
</td>
<td>
<asp:TextBox ID="flange" runat="server" Width="50" BorderStyle="None" ></asp:TextBox>
</td>
<td>
<asp:TextBox ID="hollow" runat="server" Width="50" BorderStyle="None" ></asp:TextBox>
</td>
<td>
<asp:DropDownList ID="ddl_tindakan" runat="server" Width="100" >
<asp:ListItem>Pilih..</asp:ListItem>
<asp:ListItem>Reprofiling</asp:ListItem>
<asp:ListItem>Rediscing</asp:ListItem>
</asp:DropDownList>
</td>
<td>
<asp:DropDownList ID="ddl_skid" runat="server" Width="100" >
<asp:ListItem>Pilih..</asp:ListItem>
<asp:ListItem>Ya</asp:ListItem>
<asp:ListItem>Tidak</asp:ListItem>
</asp:DropDownList>
</td>
<td>
<asp:TextBox ID="catatan" runat="server" Columns="20" Rows="5" Width="350px" Height="40" TextMode="MultiLine" BorderStyle="None" ></asp:TextBox></td>
</tr>
</table>
<br />
<input id="Button2" type="button" value="Tambah" onclick="addRow('data')" style="border: thin ridge #000000" />
<asp:Label ID="Label3" runat="server" Text="Proses" Visible="False"></asp:Label>
<br />
</asp:Panel>
<br />
<asp:Button ID="send" runat="server" Text="Hantar" BorderColor="Black" Width="60px" OnClick="Send_Click" />
<asp:Button ID="clear" runat="server" Text="Semula" BorderColor="Black" Width="60px" OnClick="Semula_Click"/><br />
Dim conn As New SqlConnection(connectionString)
conn.Open()
Dim sqlcomm As New SqlCommand("Insert into butiran_hantar ([depoh],[siriSA],[kuantiti],[date],[stokereta],[jenisroda], " +
"[nosiri],[saizroda],[flange],[hollow],[tindakan],[skid],[catatan],[status]) " +
"values (@depoh,@siriSA,@kuantiti,@date,@stokereta,@jenisroda, " +
"@nosiri,@saizroda,@flange,@hollow,@tindakan,@skid,@catatan,@status)", conn)
sqlcomm.Parameters.AddWithValue("@depoh", depohlist.SelectedValue)
sqlcomm.Parameters.AddWithValue("@siriSA", lblsiri.Text)
sqlcomm.Parameters.AddWithValue("@kuantiti", kuantiti.Text)
sqlcomm.Parameters.AddWithValue("@date", tarikh.Text)
sqlcomm.Parameters.AddWithValue("@stokereta", stokereta.Text)
sqlcomm.Parameters.AddWithValue("@jenisroda", ddl_jenisroda.SelectedValue)
sqlcomm.Parameters.AddWithValue("@nosiri", nosiri.Text)
sqlcomm.Parameters.AddWithValue("@saizroda", saizroda.Text)
sqlcomm.Parameters.AddWithValue("@flange", flange.Text)
sqlcomm.Parameters.AddWithValue("@hollow", hollow.Text)
sqlcomm.Parameters.AddWithValue("@tindakan", ddl_tindakan.SelectedValue)
sqlcomm.Parameters.AddWithValue("@skid", ddl_skid.SelectedValue)
sqlcomm.Parameters.AddWithValue("@catatan", catatan.Text)
sqlcomm.Parameters.AddWithValue("@status", "Proses")
'sqlcomm.Parameters.AddWithValue("@ulasandm", ulasandm.Text)
Try
sqlcomm.ExecuteNonQuery()
Label2.Text = "Saved."
Catch ex As Exception
Label2.Text = ex.Message.ToString()
End Try
在此先感谢
musiw.
thanks in advance
musiw.
推荐答案
没有最佳".这完全取决于您的数据要求.您可以执行任何操作,也可以将每一行存储在单独的表键中,并存储在其所属的记录中.
There is no "best". It depends entirely on your data requirements. You can do either, or you can store each line in a seperate table key''d to the record that it belongs to.
这篇关于如何从文本框&中存储多个值下拉到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文