RadioButtonList从数据库动态绑定的数据,我插入的时候有转换成float,还有错:输入字符串的格式不正确。 5
protectedvoidPage_Load(objectsender,EventArgse){conn.Open();SqlCommandcmd3=newSqlComm...
protected void Page_Load(object sender, EventArgs e)
{
conn.Open();
SqlCommand cmd3 = new SqlCommand("select * from qz1", conn);
SqlDataReader sdr3 = cmd3.ExecuteReader();
environment.DataSource = sdr3;
environment.DataTextField = "qzn";//数据库类型为float,页面显示的值
environment.DataValueField = "qzd";//数据库类型为float,插入的值
environment.DataBind();
sdr3.Close();
SqlCommand cmd4 = new SqlCommand("select * from qz1", conn);
SqlDataReader sdr4 = cmd4.ExecuteReader();
service.DataSource = sdr4;
service.DataTextField = "qzn";
service.DataValueField = "qzd";
service.DataBind();
sdr4.Close();
conn.Close();
}
protected void submit_Click(object sender, EventArgs e)
{
SqlCommand mycommand = conn.CreateCommand();
mycommand.CommandText = "insert into [user](username,password,email,consume,taste,environment,service)values(@username,@password,@email,@consume,@taste,@environment,@service)";
mycommand.Parameters.Add("@environment", SqlDbType.Float);
mycommand.Parameters.Add("@service", SqlDbType.Float);
mycommand.Parameters["@environment"].Value = Convert.ToSingle(environment.SelectedValue);
mycommand.Parameters["@service"].Value = Convert.ToSingle(service.SelectedValue);
conn.Open();
mycommand.ExecuteNonQuery();
conn.Close();
Response.Redirect("login.aspx");
} 展开
{
conn.Open();
SqlCommand cmd3 = new SqlCommand("select * from qz1", conn);
SqlDataReader sdr3 = cmd3.ExecuteReader();
environment.DataSource = sdr3;
environment.DataTextField = "qzn";//数据库类型为float,页面显示的值
environment.DataValueField = "qzd";//数据库类型为float,插入的值
environment.DataBind();
sdr3.Close();
SqlCommand cmd4 = new SqlCommand("select * from qz1", conn);
SqlDataReader sdr4 = cmd4.ExecuteReader();
service.DataSource = sdr4;
service.DataTextField = "qzn";
service.DataValueField = "qzd";
service.DataBind();
sdr4.Close();
conn.Close();
}
protected void submit_Click(object sender, EventArgs e)
{
SqlCommand mycommand = conn.CreateCommand();
mycommand.CommandText = "insert into [user](username,password,email,consume,taste,environment,service)values(@username,@password,@email,@consume,@taste,@environment,@service)";
mycommand.Parameters.Add("@environment", SqlDbType.Float);
mycommand.Parameters.Add("@service", SqlDbType.Float);
mycommand.Parameters["@environment"].Value = Convert.ToSingle(environment.SelectedValue);
mycommand.Parameters["@service"].Value = Convert.ToSingle(service.SelectedValue);
conn.Open();
mycommand.ExecuteNonQuery();
conn.Close();
Response.Redirect("login.aspx");
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询