private void combopop()
{
using (connection = new SqlConnection(connectionString))
using (SqlDataAdapter adapter = new SqlDataAdapter("Select * FROM BiludstyrTABEL", connection))
{
DataTable dt3 = new DataTable();
adapter.Fill(dt3);
OScomboBox.DataSource = dt3;
OScomboBox.ValueMember = "StregkodeID";
OScomboBox.DisplayMember = "Name";
OScomboBox.SelectedIndex = -1;
}
}
private void OScomboBox_Click(object sender, EventArgs e)
{
combopop();
}
private void OScomboBox_SelectedIndexChanged(object sender, EventArgs e)
{
OSfyld1();
}
private void OSfyld1()
{
using (connection = new SqlConnection(connectionString))
using (SqlDataAdapter adapter = new SqlDataAdapter("Select * FROM BiludstyrTABEL WHERE StregkodeID = '" + OScomboBox.SelectedIndex + "'", connection))
{
DataTable dt4 = new DataTable();
adapter.Fill(dt4);
foreach (DataRow dr in dt4.Rows)
{
OSnavntextBox.Text = dr["Navn"].ToString();
OSproducenttextBox.Text = dr["Producent"].ToString();
OSkategoritextBox.Text = dr["Kategori"].ToString();
OSprismmomstextBox.Text = dr["Pris m. Moms"].ToString();
OSantaltextBox.Text = dr["Antal"].ToString();
}
}
}
What I have tried:
When i Click my combobox dropdown arrow it displays the valuemembers (StregkodeID) in a dropdowncombobox. The OScomboBox.SelectedIndex =-1; makes all the ID's appear in the dropdownLIST, if the i didnt write this line, the first ID (the number 1 - database self identifier) would appear in the combobox when clicking the dropdown arrow.
My problem: When click the ID 2 (second line on the ID list - of course) it displays the first entry in the database (it display the entry of the FIRST database entry) !!
The index is shiftet when populating the combobox right? So that the first entry from the database is set to index 0 of the combobox? When i click the ID of 1, nothing appears (my textboxes are empty). SO every time i pick an ID in the combobox it displays the data of the prior index (pick 2 get 1, pick 5 get 4 and so on).
Been working on this for several days, and cant seem to find any answers. PLEASE HELP!