in my litte project, I have two listview and two db. First listview is fill from the first database table. the second is fill from the first selected item.
The two listboxes are built in same mode:
`name | surname | id`.
In the first listbox I have the list of all the users insert in the db
`Ale | Zucchelli | 5`
`Faby | Jake | 6`
`Alexa | Doctor | 7`
`Mattias | Rossi | 12`
When I select an element an click on the move button, the select item move to the second listbox.
second listbox items
`Ale | Zucchelli | 5`
`Mattias | Rossi | 12`
When I click on Insert button, the items of the second listbox I must send it to second table of my db, but I must to register only the the id.
I have try this code:
private void btmconferma_Click(object sender, EventArgs e) {
string idutente;
//string idu_retrive = string.Empty;
//object value = 0;
idutente = user.Text;
//string querysql2 = " INSERT INTO AMICIZIA (IdUtente1, [idamici]) VALUES ('" + idutente + "', '" + value + "')";
//SqlConnection myconn = new SqlConnection(CnnStr);
//SqlCommand mycmd = new SqlCommand(querysql2, myconn);
foreach (ListViewItem l in listamicizie.Items)
{
string CnnStr = System.Configuration.ConfigurationSettings.AppSettings["CnnStr"].ToString();
SqlConnection myconn = new SqlConnection(CnnStr);
myconn.Open();
SqlCommand cmd = new SqlCommand("insert into AMICIZIA (IdUtente1) values('" + idutente + "')", myconn);
//SqlCommand cmd1 = new SqlCommand("insert into AMICIZIA (idamici) values('" + l.SubItems["IdUtente"].ToString() + "')", myconn);
SqlCommand cmd1 = new SqlCommand("insert into AMICIZIA (idamici) values('" + listamicizie.Columns["IdUtente"].Text + "')", myconn);
cmd.ExecuteNonQuery();
cmd1.ExecuteNonQuery();
myconn.Close();
}
this.Close();
}
The value of IdUtente is right, but the value of idamici is always zero. How that i do?