将 radiobutton 的 text 值写入到数据库 sql server 的代码
2014-05-08 22:58
程序代码:
try
{
foreach (Control ct in this.panel1.Controls)
{
if (ct is RadioButton && (ct as RadioButton).Checked)
{
using (System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection("连接字符串"))
{
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("insert into ...", con);
con.Open();
if (cmd.ExecuteNonQuery() > 0)
{
MessageBox.Show("OK");
}
else
{
MessageBox.Show("失败", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
con.Close();
}
return;
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

2014-05-09 08:35
2014-05-09 16:49

2014-05-09 20:55
2014-05-12 08:25

2014-05-12 08:28
2014-05-12 20:55