You are inserting value as String
in the database, and then trying to add values as Integer
the wrong way
to properly insert value as integer
cmd.CommandText = "INSERT INTO Table1(kat) VALUES(@id)";
cmd.Parameters.AddWithValue("@id", listBox1.SelectedIndex);
cmd.ExecuteNonQuery();
The to create the copy of the listBox on other form you can do so by using a SELECT
query.
Ex.
cmd.CommandText = "SELECT kat FROM Table1";
var reader = cmd.ExecuteReader();
while(reader.Read())
{
otherListBox.Items.Add(reader[0]);
}
reader.Close();
To sync the list , try this
int index = listBox1.FindStringExact("id to find");
if (index > -1)
{
listBox1.SelectedIndex = index;
}