如何将radioputton值输入数据库 [英] how to inser radiobutton value into database

查看:121
本文介绍了如何将radioputton值输入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将我为单选按钮设置的值插入数据库。

我在构建项目时遇到错误:运算符''&''未定义类型''String''和''System.web.ui.attributecollection''



我在pageload上设置了收音机的值:

  Dim  RBS  As  RadioButton =  CType (TypeForm.FindControl(  RBS),RadioButton )
RBS.Attributes.Add( value S





cmd。 CommandText =INSERT INTO PTPropertyType(PTTypeName,PTType,PTSM,PTAudit,PTUser)VALUES(''& name.Text&'','''& type.Text&'', ''& RBS.Attributes [value ] .ToString()&'' GetDate(),''&会话(UserInfo)& '')



有办法做到这一点吗?

解决方案

传递值检查为变量时收音机

示例



<前lang =vb> 昏暗 ValueCheck as String =
如果 Radio.Checked = true 然后 ValueCheck = S 其他 ValueCheck = N

cmd.CommandText = INSERT INTO PTPropertyType(PTTypeName,PTType,PTSM,PTAudit,PTUser )VALUES('& name.Text& ','& type.Text& ','& ValueCheck& ',GetDate(),'&会话( UserInfo)& ')


I want to insert the value i set for a radio button into database.
I get the error on building my project: operator ''&'' is not defined for types ''String'' and ''System.web.ui.attributecollection''

I set the value of the radio on pageload:

Dim RBS As RadioButton = CType(TypeForm.FindControl("RBS"), RadioButton)
RBS.Attributes.Add("value", "S")



cmd.CommandText = "INSERT INTO PTPropertyType (PTTypeName, PTType, PTSM, PTAudit, PTUser) VALUES (''" & name.Text & "'', ''" & type.Text & "'', ''" & RBS.Attributes["value"].ToString() & "'', GetDate(), ''" & Session("UserInfo") & "'')"

is there a way to do this?

解决方案

Pass the value of the radio when checked as variable
example

Dim ValueCheck as String = ""
If Radio.Checked = true Then ValueCheck = "S" Else ValueCheck = "N"
 
cmd.CommandText = "INSERT INTO PTPropertyType (PTTypeName, PTType, PTSM, PTAudit, PTUser) VALUES ('" & name.Text & "', '" & type.Text & "', '" & ValueCheck  & "', GetDate(), '" & Session("UserInfo") & "')"


这篇关于如何将radioputton值输入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆