Click here to Skip to main content
15,881,681 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
ERROR:-No mapping exists from object type System.Data.DataRowView to a known managed provider native type.

code following:-
C#
con.Open();
           SqlCommand cmd = new SqlCommand("addprd1", con);
           cmd.CommandType = CommandType.StoredProcedure;
           cmd.Connection = con;
           cmd.Parameters.AddWithValue("@id", label10.Text);
           cmd.Parameters.AddWithValue("@srno", textBox1.Text);
           cmd.Parameters.AddWithValue("@itm", comboBox1.SelectedItem);
           cmd.Parameters.AddWithValue("@make", comboBox2.SelectedItem);
           cmd.Parameters.AddWithValue("@dop", dateTimePicker1.Text);
           cmd.Parameters.AddWithValue("@year", comboBox3.SelectedItem);
           cmd.Parameters.AddWithValue("@mno", textBox6.Text);
           cmd.Parameters.AddWithValue("@srm", textBox7.Text);
           cmd.Parameters.AddWithValue("@off", textBox9.Text);
           cmd.Parameters.AddWithValue("@usr", textBox8.Text);
           cmd.ExecuteNonQuery();
           con.Close();
           label10.Visible = true;
           MessageBox.Show("Insert Successfully");
           Bind();
           label10.Visible = false;
           Clear();



Edit : Code Block added
Posted
Updated 30-Jun-14 21:50pm
v2

comboBox1.SelectedItem may not necessarily be a string, the data type depends on how the control was actually data bound, try comboBox1.Text instead or cast the SelectedValue to the appropriate type.

DataRowView drv = (DataRowView) comboBox1.SelectedValue
 
Share this answer
 
Comments
Nishant.Chauhan80 1-Jul-14 4:53am    
Thanks combobox1.text its working
Just a guess, but it's probably the combobox values.
It looks like you have bound data to the combobox, and as a result the SelectedItem is a DataRowView object (which it will be).
You need to get the information from that row which matches the datatype in your DB - I can't tell you exactly what to do as I have no idea what data you have loaded, or what data you have in your DB.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900