Error: No mapping exists from object type System.Web.UI.WebControls.ListItem to a known managed provider native type in ASP.Net

Last Reply on Apr 03, 2017 04:09 AM By AnkitPal

Posted on Apr 03, 2017 03:48 AM

Calling Procedure -

 

ALTER PROCEDURE [dbo].[AddUser]

      @UniqueId NVARCHAR(50),
      @UniquePwd NCHAR(10),
      @Depart NVARCHAR(120),
      @UserName NVARCHAR(80),
      @ECCRegdId NVARCHAR(10),
      @Email NVARCHAR(180),
      @NameCate NCHAR(10),
      @Name NVARCHAR(120),
      @FhCate NCHAR(10),
      @FhName NVARCHAR(120),
      @Mobile NCHAR(10),
      @Gender NCHAR(10),
      @DOB NCHAR(10),
      @VerifyEmail NVARCHAR(50),
      @Depart_Head NCHAR(10),
      @col3 NCHAR(10),
      @RecordDateTime DATETIME
AS
BEGIN
      SET NOCOUNT ON;
      INSERT INTO dbo.EccChat_User(UniqueId, UniquePwd, Depart, UserName, ECCRegdId, Email, NameCate, Name, FhCate, FhName, Mobile, Gender, DOB, VerifyEmail, Depart_Head, col3, RecordDateTime)
      
      VALUES (@UniqueId, @UniquePwd, @Depart, @UserName, @ECCRegdId, @Email, @NameCate, @Name, @FhCate, @FhName, @Mobile, @Gender, @DOB, @VerifyEmail, @Depart_Head, @col3, @RecordDateTime)
END
GO

Code Behind - 

 

protected void btnsave_Click(object sender, System.EventArgs e)
        {
            SqlConnection cnn = new SqlConnection();
            cnn.ConnectionString=System.Configuration.ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
            
            SqlCommand cmd = new SqlCommand();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "AddChatUser";
            cmd.Parameters.AddWithValue("@UniqueId", newCID);
            cmd.Parameters.AddWithValue("@UniquePwd", RandomPassword());
            cmd.Parameters.AddWithValue("@Depart", ddl_chatdept.SelectedItem);
            cmd.Parameters.AddWithValue("@UserName", txtun.Text);
            cmd.Parameters.AddWithValue("@ECCRegdId", txtEccRegdId.Text);
            cmd.Parameters.AddWithValue("@Email", txtEmail.Text);
            cmd.Parameters.AddWithValue("@NameCate", ddl_namecate.SelectedItem);
            cmd.Parameters.AddWithValue("@Name", txtname.Text);
            cmd.Parameters.AddWithValue("@FhCate", ddl_fhnamecate.SelectedItem);
            cmd.Parameters.AddWithValue("@FhName", txtfhname.Text);
            cmd.Parameters.AddWithValue("@Mobile", txtmobile.Text);
            cmd.Parameters.AddWithValue("@Gender", ddl_gender.SelectedItem);
            cmd.Parameters.AddWithValue("@DOB", txtDOB.Text);
            cmd.Parameters.AddWithValue("@VerifyEmail", "Pending");
            cmd.Parameters.AddWithValue("@Depart_Head", ddl_chatdept.SelectedValue);
            cmd.Parameters.AddWithValue("@col3", "Null");
            cmd.Parameters.AddWithValue("@RecordDateTime", DateTime.Now);
            cmd.Connection = cnn;
            cnn.Open();
            cmd.ExecuteNonQuery();
            cnn.Close();
        }

 

You are viewing reply posted by: AnkitPal on Apr 03, 2017 04:09 AM.
Posted on Apr 03, 2017 04:09 AM
Andrea says:
Hi @AnkitPal,
Please try the following

C# No mapping exists from object type System.Data.DataRowView to a known managed provider native type.

It might help you.

Cheers Andrea.

 I solve this issue to change few codes as like below-

Before code -

 

cmd.Parameters.AddWithValue("@Depart", ddl_chatdept.SelectedItem);

Now Code -

 

cmd.Parameters.AddWithValue("@Depart", ddl_chatdept.SelectedItem.ToString());

This is working fine.