ListItem存在一个已知的托管提供原生型

ListItem存在一个已知的托管提供原生型

本文介绍了没有映射从对象类型System.Web.UI.WebControls.ListItem存在一个已知的托管提供原生型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 保护无效btnsubmit_Click(对象发件人,EventArgs的发送)
    {
        如果(rbtmale.Checked)
        {
            性别=男;
        }
        否则,如果(rbtfemale.Checked)
        {
            性别=女;
        }
        如果(cbxsd.Checked)
        {
            指定=SD;
        }
        否则,如果(cbxasd.Checked)
        {
            指定=ASD
        }
        否则,如果(cbxtrainee.Checked)
        {
            指定=实习生;
        }
        如果(cbxbsc.Checked)
        {
            QUA =学士;
        }
        否则,如果(cbxbca.Checked)
        {
            QUA =BCA;
        }
        否则,如果(cbxbtech.Checked)
        {
            QUA =技术学士;
        }
        否则,如果(cbxmca.Checked)
        {
            QUA =MCA
        }
        否则,如果(cbxmba.Checked)
        {
            QUA =MBA;
        }        SqlConnection的CON =新的SqlConnection(S1);
        CMD的SqlCommand =新的SqlCommand(SP_2CON);
        cmd.CommandType = CommandType.StoredProcedure;
        con.Open();
        cmd.Parameters.AddWithValue(@ ID,txtid.Text.Trim());
        cmd.Parameters.AddWithValue(@名,txtname.Text.Trim());
        cmd.Parameters.AddWithValue(@时代,txtage.Text.Trim());
        cmd.Parameters.AddWithValue(@性,性别等);
        cmd.Parameters.AddWithValue(@地址,txtaddr.Text.Trim());
        cmd.Parameters.AddWithValue(@ HQ,QUA);
        cmd.Parameters.AddWithValue(@公司,ddlcompany.SelectedItem);
        cmd.Parameters.AddWithValue(@ DESIG称号);
        cmd.Parameters.AddWithValue(@暴民,txtmob.Text.Trim());
        cmd.Parameters.AddWithValue(@电子邮件,txtemail.Text.Trim());
        cmd.Parameters.Add(@味精,SqlDbType.VarChar,20)= .Direction ParameterDirection.Output;
        cmd.ExecuteNonQuery();
        //如果(ⅰ大于0)
        // {
        // Label1.Text =插入成功;
        //}
        //其他
        // {
        // Label1.Text =无法插入
        //}
        。字符串s2 = cmd.Parameters [@味精] Value.ToString();
        回复于(S2);
        con.Close();
    }


解决方案

我想我看到的问题:

  cmd.Parameters.AddWithValue(@公司,ddlcompany.SelectedItem);

ddlcompany.SelectedIndex ddlcompany.SelectedValue ...

ddlcompany.SelectedItem被引用列表项本身,而不是一个值。

protected void btnsubmit_Click(object sender, EventArgs e)
    {
        if (rbtmale.Checked)
        {
            gender = "male";
        }
        else if(rbtfemale.Checked)
        {
            gender = "female";
        }
        if (cbxsd.Checked)
        {
            designation = "sd";
        }
        else if (cbxasd.Checked)
        {
            designation = "asd";
        }
        else if (cbxtrainee.Checked)
        {
            designation = "trainee";
        }
        if (cbxbsc.Checked)
        {
            qua = "BSc";
        }
        else if (cbxbca.Checked)
        {
            qua = "BCA";
        }
        else if (cbxbtech.Checked)
        {
            qua = "BTech";
        }
        else if (cbxmca.Checked)
        {
            qua = "MCA";
        }
        else if (cbxmba.Checked)
        {
            qua = "MBA";
        }



        SqlConnection con = new SqlConnection(s1);
        SqlCommand cmd = new SqlCommand("sp_2", con);
        cmd.CommandType = CommandType.StoredProcedure;
        con.Open();
        cmd.Parameters.AddWithValue("@id", txtid.Text.Trim());
        cmd.Parameters.AddWithValue("@name",txtname.Text.Trim());
        cmd.Parameters.AddWithValue("@age",txtage.Text.Trim());
        cmd.Parameters.AddWithValue("@sex",gender);
        cmd.Parameters.AddWithValue("@addr",txtaddr.Text.Trim());
        cmd.Parameters.AddWithValue("@hq",qua);
        cmd.Parameters.AddWithValue("@company",ddlcompany.SelectedItem);
        cmd.Parameters.AddWithValue("@desig",designation);
        cmd.Parameters.AddWithValue("@mob",txtmob.Text.Trim());
        cmd.Parameters.AddWithValue("@email", txtemail.Text.Trim());
        cmd.Parameters.Add("@msg", SqlDbType.VarChar, 20).Direction = ParameterDirection.Output;
        cmd.ExecuteNonQuery();
        //if (i > 0)
        //{
        //    Label1.Text = "successfully inserted";
        //}
        //else
        //{
        //    Label1.Text = "failed to insert";
        //}
        string s2 = cmd.Parameters["@msg"].Value.ToString();
        Response.Write(s2);
        con.Close();
    }
解决方案

I think I see the problem:

cmd.Parameters.AddWithValue("@company",ddlcompany.SelectedItem);

Should be ddlcompany.SelectedIndex or ddlcompany.SelectedValue...

ddlcompany.SelectedItem is referencing the ListItem itself, not a value.

这篇关于没有映射从对象类型System.Web.UI.WebControls.ListItem存在一个已知的托管提供原生型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 02:53