Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
602 views
in Technique[技术] by (71.8m points)

c# - ERROR : No mapping exists from object type System.Data.DataRowView to a known managed provider native type

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 button1_Click(object sender, EventArgs e)
    {
        String connectionString = @"Connection String Here ";
        SqlConnection connection = new SqlConnection(connectionString);
        connection.Open();

        // INSERTION 
        string query = "INSERT INTO StudentMaster(RollNo,Name,Gender,FathersName,Course,Branch,Semester,Section,ContactNo1,ContactNo2,EmailId) VALUES ('" + textBox1.Text + "', '" + textBox2.Text + "', @Gender,'" + textBox3.Text + "', '" + comboBox1.Text + "','" + comboBox2.Text + "', '" + comboBox3.Text + "', '" + comboBox4.Text + "','" + textBox4.Text + "', '" + textBox5.Text + "', '" + textBox6.Text + "'";
        SqlCommand command = new SqlCommand(query, connection);

        // Radio button
        if (radioButton1.Checked)
        {
            command.Parameters.AddWithValue("@Gender", "Male");
        }
        else
        {
            command.Parameters.AddWithValue("@Gender", "Female");
        }

        // value store for combobox
        //command.Parameters.AddWithValue("@DOB", dateTimePicker1.Text);
        command.Parameters.AddWithValue("@Course", comboBox1.SelectedItem);
        command.Parameters.AddWithValue("@Branch", comboBox2.SelectedItem);
        command.Parameters.AddWithValue("@Semester", comboBox3.SelectedItem);
        command.Parameters.AddWithValue("@Section", comboBox4.SelectedItem);

        command.ExecuteNonQuery();
        connection.Close();

        if (MessageBox.Show("Do you really want to INSERT??", "Insert", MessageBoxButtons.OKCancel) == DialogResult.OK)
        {
            MessageBox.Show("INSERTED");
        }
    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

SelectedValue is an object of the class that is used as DataRowView view of a DataRow and should be used in the same way, namely: ? DataRowView drv = (DataRowView) comboBox1.SelectedValue;


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...