Note that there are some explanatory texts on larger screens.

plurals
  1. POThe multi-part identifier "System.Data.DataRowView" could not be bound #2
    primarykey
    data
    text
    <p>I know this is a duplicate to some questions here, but believe me I've tried all of them, and no luck.</p> <p>I am new to C#+MySQL.</p> <p>I have a database with 2 tables, programmers and softwares. I have a column in the softwares table named programmersid. It's one to many relation. I have two listboxes. The first one is with the programmers name, and when I click on a programmer, it's showing me the softwares that he has made.</p> <p>When I click on a software, the text will be put into a textbox, and I have an update button. When I click it, it should update the name of that software.</p> <p>Here is my code:</p> <pre><code>public partial class Form1 : Form { private DataSet ds; private SqlConnection conn; private SqlDataAdapter programmersadapter; private SqlDataAdapter softwaresadapter; protected string connectionString = "Data Source=ICEBOX19-PC\\ICEBOX;Initial Catalog=software;Integrated Security=True"; public Form1() { InitializeComponent(); conn = new SqlConnection(connectionString); SqlCommand programmersselect = new SqlCommand("SELECT ID, Name FROM programmers", conn); programmersadapter = new SqlDataAdapter(programmersselect); SqlCommand softwaresselect = new SqlCommand("SELECT name FROM softwares WHERE programmerid = @ID", conn); softwaresselect.Parameters.Add(new SqlParameter("@ID", SqlDbType.Int)); softwaresadapter = new SqlDataAdapter(softwaresselect); showme(); } private void showme() { ds = new DataSet(); conn.Open(); programmersadapter.Fill(ds, "programmers"); conn.Close(); listBox1.ValueMember = "id"; listBox1.DisplayMember = "name"; listBox1.DataSource = ds.Tables["programmers"]; } private void Form1_Load(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { conn.Open(); SqlCommand command = new SqlCommand("update softwares set name='" + textBox1.Text + "' where programmerid=" + listBox2.SelectedValue.ToString(), conn); command.ExecuteNonQuery(); conn.Close(); reload(); } private void reload() { //listBox2.SelectedIndexChanged -= listBox2_SelectedIndexChanged; softwaresadapter.SelectCommand.Parameters["@id"].Value = listBox1.SelectedValue; var table = new DataTable(); softwaresadapter.Fill(table); conn.Close(); listBox2.DisplayMember = "name"; listBox2.ValueMember = "id"; listBox2.DataSource = table; //listBox2.SelectedIndexChanged += listBox2_SelectedIndexChanged; } private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { reload(); } private void listBox2_SelectedIndexChanged(object sender, EventArgs e) { textBox1.Text = listBox2.Text; textBox1.Text = textBox1.Text.Replace(" ", ""); } } </code></pre> <p>I get this exception: </p> <blockquote> <p>The multi-part identifier "System.Data.DataRowView" could not be bound.</p> </blockquote> <p>It comes from the <code>command.ExecuteNonQuery()</code> in the <code>button1.Click</code>.</p> <p>I've tried to change the :</p> <pre><code>SqlCommand command = new SqlCommand("update softwares set name='" + textBox1.Text + "' where programmerid=" + listBox2.SelectedValue, conn); </code></pre> <p>to</p> <pre><code>SqlCommand command = new SqlCommand("update softwares set name='" + textBox1.Text + "' where programmerid=" + listBox2.SelectedValue.ToString(), conn); </code></pre> <p>But I also get the same thing. Do you guys have some ideas ? I am looking for this since 2 hours now.</p> <p><strong>PS: I get the same error even if I try to delete</strong></p> <pre><code> private void delete_Click(object sender, EventArgs e) { conn.Open(); SqlCommand command = new SqlCommand("delete from softwares where id="+listBox2.SelectedItem, conn); command.ExecuteNonQuery(); conn.Close(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload