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

Posted by Sudheep.grandhe under C# on 11/3/2011 | Points: 10 | Views : 6343 | Status : [Member] | Replies : 2
Hi,

It shows the error like this.
Error:-No mapping exists from object type System.Data.DataRowView to a known managed provider native type.I am underlying the error part.

private void cmb_companyname_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("data source=mars-104;initial catalog=marsweb;integrated security=true");

//DBConnection db = new DBConnection();

//SqlConnection con = db.opencon();
SqlCommand cmd = new SqlCommand("select custaddress from tbl_customer where custname=@custname", con);
cmd.Parameters.AddWithValue("@custname", cmb_companyname.SelectedValue );
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
txt_customeraddress.Text = dt.Rows[0][1].ToString();
}
}

Best,
Sudheep.



Responses

Posted by: Blessyjees on: 11/4/2011 [Member] Bronze | Points: 25

Up
0
Down
hi,

you didn't open the sql connetion in your code. add this con.Open() as the second line and try again.

Blessy Baby
Digitalmesh Softech pvt Ltd
https://blessybaby.wordpress.com/

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sudheep.grandhe on: 11/4/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

If i change the code as you mentioned in previous.it shows the same error.

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

Best,
Sudheep.

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response