主题:  关于RadioButton存到数据库的问题

eShaka

职务:版主
等级:6
金币:15.0
发贴:5019
#12004/10/10 20:51:21
两个RadioButton为一组,一个boy,一个girl,当选择一个的时候把text值存到数据库,可我做的不行:(,


		private void hand_Click(object sender, System.EventArgs e)
		{
			string strInsert;
			SqlCommand contactInsert;

			strInsert = "Insert contact ( name,sex,qq,msn,mail,url,message,date_hand ) Values ( @name,@sex,,@qq,@msn,@mail,@url,@message,@date_hand )";
			contactInsert = new SqlCommand( strInsert, sqlConnectionContact );
			contactInsert.Parameters.Add( "@name", SqlDbType.Char ).Value = name.Text;
			contactInsert.Parameters.Add( "@boy", SqlDbType.Char ).Value = boy.Text;
			contactInsert.Parameters.Add( "@sex", SqlDbType.Char ).Value = qq.Text;
			contactInsert.Parameters.Add( "@msn", SqlDbType.Char ).Value = msn.Text;
			contactInsert.Parameters.Add( "@mail", SqlDbType.Char ).Value = mail.Text;
			contactInsert.Parameters.Add( "@url", SqlDbType.Char ).Value = url.Text;
			contactInsert.Parameters.Add( "@message", SqlDbType.VarChar ).Value = message.Text;
			contactInsert.Parameters.Add( "@date_hand", SqlDbType.DateTime ).Value = DateTime.Now;

			sqlConnectionContact.Open();
			contactInsert.ExecuteNonQuery();
			sqlConnectionContact.Close();
		}


																	<td width="144"><FONT face="&Euml;&Icirc;&Igrave;&aring;">
																			<asp:RadioButton id="boy" runat="server" Text="Boy" GroupName="sex"></asp:RadioButton>
																			<asp:RadioButton id="girl" runat="server" Text="Girl" GroupName="sex"></asp:RadioButton></FONT></td>

编辑历史:[此帖最近一次被 lemontree 编辑过(编辑时间:2004-10-11 09:37:31)]


蓝鲸

职务:版主
等级:5
金币:42.1
发贴:2614
#22004/10/11 1:10:51
string strSex;
if ( Boy.Checked )
{
    strSex = Boy.Text;
}
else if ( Girl.Checked )
{
    strSex = Girl.Text;
}

也觉有些罗嗦,但一时还想不出好办法,将就用吧。想到时再改代码。


非常大鱼