如何解决这个插入查询 [英] how to solve this for insert query
本文介绍了如何解决这个插入查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
错误: - 从对象类型System.Data.DataRowView到已知托管提供者本机类型的映射不存在。
代码如下: -
ERROR:-No mapping exists from object type System.Data.DataRowView to a known managed provider native type.
code following:-
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
推荐答案
comboBox1.SelectedItem
可能不一定是字符串,数据类型取决于控件实际数据绑定的方式,请尝试comboBox1.Text
而是将SelectedValue转换为适当的类型。
comboBox1.SelectedItem
may not necessarily be a string, the data type depends on how the control was actually data bound, trycomboBox1.Text
instead or cast the SelectedValue to the appropriate type.
DataRowView drv = (DataRowView) comboBox1.SelectedValue
只是一个猜测,但它可能是组合框的值。
看起来你已经将数据绑定到组合框了,因此,SelectedItem是一个DataRowView对象(它将是)。
您需要从该行获取与您的数据库中的数据类型匹配的信息 - 我无法准确地告诉您我不知道你加载了什么数据,或者数据库中有什么数据。
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.
这篇关于如何解决这个插入查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文