asp.net中的RadioButtonList。我希望可以提取出选择的RadioButtonList的值存到数据库you里面的system表格

2024-11-29 07:11:06
推荐回答(2个)
回答1:

//因为你的RadioButtonList的项有value和Text属性,所以可以这样写
string strItem = null;  //声明变量保存RadioButtonList选中的值
strItem = RadioButtonList.SelectedValue.ToString();  //获取选中的Value值
//如果RadioButtonList的项没有Value和Text的话,则要循环 
//for(int i=0;i//{ 
   //if(RadioButtonList1.Items[i].Selected==true)
   //{ 
      ////获取选中的值
      //strItem = RadioButtonList.Items[i].Text.ToString(); 
   //}  
//} 
//以下是数据库操作
//声明数据库连接字符串(这个你就自己写啦)
string strCon="";
//声明数据库操作语句(其中Field是你表中的字段名)   
string strSql="insert into system(Field) values ('"+strItem+"')";
//声明数据库连接对象实例
System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(strCon);
con.Open();  //打开连接
//声明数据库操作对象实例
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(strSql,con);
//通过操作对象执行数据库操作
cmd.ExecuteNonQuery(); 
con.Close();   //关闭连接
Response.Write("alert('数据插入成功');");    //客户端消息框

有问题再hi我吧

回答2:

system表只有一个字段吗?