I am trying to save radio button selected value to database; not sure how to do that. I found the C# code shown here on Google, I need to modify it so that if three sets of radio buttons are set, I need to save all radio button selected values to database using 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();
}
}