gpt4 book ai didi

C# 将每个单选按钮选定的数据保存到数据库

转载 作者:行者123 更新时间:2023-11-29 21:43:27 26 4
gpt4 key购买 nike

我正在尝试将单选按钮选定的值保存到数据库;不知道该怎么做。我在 Google 上找到了此处显示的 C# 代码,我需要对其进行修改,以便如果设置了三组单选按钮,我需要使用 foreach 将所有单选按钮选定的值保存到数据库中。

<table id='attendence'>
<tr>
<td>
<input type="text" readonly="readonly" value="12KQA60079">
</td>
<td>
<input type="text" readonly="readonly" value="ARUNA S">
</td>
<th>
<input type="radio" class="present" name="Present1" value="Present">
</th>
<th>
<input type="radio" class="absent" name="Present1" value="Absent">
</th>
<th>
<input type="radio" class="leave" name="Present1" value="Leave">
</th>
</tr>
<tr>
<td>
<input type="text" readonly="readonly" value="12KQA60080">
</td>
<td>
<input type="text" readonly="readonly" value="ASHWINI S M">
</td>
<th>
<input type="radio" class="present" name="Present2" value="Present">
</th>
<th>
<input type="radio" class="absent" name="Present2" value="Absent">
</th>
<th>
<input type="radio" class="leave" name="Present2" value="Leave">
</th>
</tr>
<tr>
<td>
<input type="text" readonly="readonly" value="12KQA60220">
</td>
<td>
<input type="text" readonly="readonly" value="Das">
</td>
<th>
<input type="radio" class="present" name="Present3" value="Present">
</th>
<th>
<input type="radio" class="absent" name="Present3" value="Absent">
</th>
<th>
<input type="radio" class="leave" name="Present3" value="Leave">
</th>
</tr>
</table>

C#

string sql = "INSERT INTO MyTable (Col1, Col2) VALUES (@attendence, @username)"; 

using (MySqlConnection con = new MySqlConnection(connectionString))
{
int retvalue;
con.Open();

foreach (DataRow row in myTable.Rows)
{
MySqlCommand myCommand = new MySqlCommand();
myCommand.Connection = con;
myCommand.CommandText = sql;
myCommand.Parameters.AddWithValue("@attendence", r["attendence"]);
myCommand.Parameters.AddWithValue("@username", r["username"]);
retvalue = myCommand.ExecuteNonQuery();
}
}

最佳答案

给出 的 id/名称。您可以使用该 ID 来获取用户名以及获取出席/缺席/离开状态。

<input id="username1" type="text" readonly="readonly" value="ARUNA S">
<input id="radio1" type="radio" class="present" name="Present2" value="Present">
<input id="radio2" type="radio" class="absent" name="Present2" value="Absent">
<input id="radio3" type="radio" class="leave" name="Present2" value="Leave">

获取用户名

 username1.text

获取状态为 -

if(radio1.checked)
attendance=radio1.value
else if(radio2.checked)
attendance=radio2.value
else if(radio3.checked)
attendance=radio3.value

关于C# 将每个单选按钮选定的数据保存到数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34286384/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com