Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

SqlDataReader for combobox

$
0
0

public void udelej_vzor() { try { SqlCommand novyprikaz = new SqlCommand("SELECT * FROM zajezd WHERE akce=" + nc_zajezd_vyber, spojeni); spojeni.Open(); SqlDataReader precti = novyprikaz.ExecuteReader(); if (precti.Read()) { comboBox1.SelectedValue = precti.GetInt32(25).ToString(); } }

Hello guys, I have got this code, It should select combobox value but it doesn't. I have Value klimax in table zajezd which is under column number 25. This value  is also in table named busnaz but under name pocsed. In combobox are varchar values from table busnaz and column nazev.

I would like the combobox select automatically value which is in the same row but different value. Value in combobox is char and in pocsed is int.

Would someone help me solve this out?

Thanks in advance

edit: this is the sql statement for fill the combobox

try
            {
                SqlDataReader dr = combobox.ExecuteReader();
                while (dr.Read())
                {
                    comboBox1.Items.Add(dr["nazev"]);

                }

                dr.Close();
                dr.Dispose();
                spojeni.Close();
            }



Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>