-1

こんにちは、次のようなエラーが表示されます......
エラー:- オブジェクト型 System.Data.DataRowView から既知のマネージド プロバイダー ネイティブ型へのマッピングは存在しません。エラー部分の根底にあるのは…………!!

    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");
        }
    }
4

2 に答える 2

1

SelectedValue は、DataRow の DataRowView ビューとして使用されるクラスのオブジェクトであり、同じ方法で使用する必要があります。

于 2013-10-02T09:33:34.173 に答える