开发者

No mapping exists from object type System.Web.UI.WebControls.ListItem to a known managed provider native type

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;
        co开发者_StackOverflow社区n.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.


Just change this below line of code

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

to

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

It will work as SelectedItem need to be converted in string type

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜