Gökmen Anıl Yılmaz
asked on
c# combobox and datetime picker for sql server
hi;
my win form have 2 combobox and 2 datetime picker i and ComboBox2 is filling up according to ComboBox1 no problem but want Filling 2 DateTimePicker according to ComboBox 2
private void Stok_Load(object sender, EventArgs e)
{
SqlDataAdapter sda = new SqlDataAdapter("SELECT DISTINCT MARKA FROM tbl_markamodel", baglanti);
DataTable dt = new DataTable();
sda.Fill(dt);
markacombo.Items.Add("---S ELECT---") ;
foreach (DataRow ROW in dt.Rows)
{
markacombo.Items.Add(ROW[" MARKA"].To String());
}
}
private void markacombo_SelectedIndexCh anged(obje ct sender, EventArgs e)
{
SqlDataAdapter sda = new SqlDataAdapter("select distinct model from tbl_markamodel where marka='" +markacombo.Text+"'",bagla nti);
DataTable dt = new DataTable();
sda.Fill(dt);
foreach (DataRow ab in dt.Rows)
{
modelcombo.Items.Add(ab["m odel"].ToS tring());
}
}
my win form have 2 combobox and 2 datetime picker i and ComboBox2 is filling up according to ComboBox1 no problem but want Filling 2 DateTimePicker according to ComboBox 2
private void Stok_Load(object sender, EventArgs e)
{
SqlDataAdapter sda = new SqlDataAdapter("SELECT DISTINCT MARKA FROM tbl_markamodel", baglanti);
DataTable dt = new DataTable();
sda.Fill(dt);
markacombo.Items.Add("---S
foreach (DataRow ROW in dt.Rows)
{
markacombo.Items.Add(ROW["
}
}
private void markacombo_SelectedIndexCh
{
SqlDataAdapter sda = new SqlDataAdapter("select distinct model from tbl_markamodel where marka='" +markacombo.Text+"'",bagla
DataTable dt = new DataTable();
sda.Fill(dt);
foreach (DataRow ab in dt.Rows)
{
modelcombo.Items.Add(ab["m
}
}
How would the datetime pickers be populated based on what's selected in the second combobox modelcombo?
ASKER
Could you suggest another solution because I do not know by: Geert G
ASKER
my database table 4 column marka model date1 date2.
1. ComboBox is filling up the selected 2. ComboBox and I want to fill the selected 2.combobox with datetimepicker and datetimepicker 2
by: Norie
1. ComboBox is filling up the selected 2. ComboBox and I want to fill the selected 2.combobox with datetimepicker and datetimepicker 2
by: Norie
Will the second combobox be populated with multiple values?
If so, what exactly do you want to show in the datetime pickers?
If so, what exactly do you want to show in the datetime pickers?
ASKER
1. combobox 10 values and 2. combobox i think 50 values.
model production and end date
model production and end date
If there are 50 values in the 2nd combobox it implies they came from 50 records in the database, and each of those records will have 2 time values.
So what value(s) should go in the datetimepickers?
Should they be populated based on which value is selected in the second combobox?
If that's the case I would suggest you populate the second combobox with the values from model and both date columns.
So what value(s) should go in the datetimepickers?
Should they be populated based on which value is selected in the second combobox?
If that's the case I would suggest you populate the second combobox with the values from model and both date columns.
ASKER
If there are 50 values in the 2nd combobox it implies they came from 50 records in the database, and each of those records will have 2 time values. YES
this pic my table
1.combobox marka
2. combobox model
and 2datetimepicker
i choose combobox 1 value and i fill combobox 2 but i dont fill datetimepicker
database.png
this pic my table
1.combobox marka
2. combobox model
and 2datetimepicker
i choose combobox 1 value and i fill combobox 2 but i dont fill datetimepicker
database.png
So if FIAT was selected from the first combobox (markacombo) and 127 from the second combobox (modelcombo) you would want the datetime pickers populated with the dates 1971-06-01 and 1986-02-01?
ASKER
Yes that's right
ASKER
but how can i :)
You could use the SelectedIndexChanged event of the 2nd combobox to run another query and return the dates.
Something like this perhaps.
Something like this perhaps.
private void modelcombo_SelectedIndexChanged(object sender, EventArgs e)
{
SqlDataAdapter sda = new SqlDataAdapter("select uretimtarihi, bitisitetarihi from tbl_markamodel where marka='" +markacombo.Text+"' AND model='"+modelcombo.Text +"'",baglanti);
' code to set values of datetime pickers.
}
ASKER
i know but i do not know
this code
I wrote here my fault
' code to set values of datetime pickers.
can you say
this code
I wrote here my fault
' code to set values of datetime pickers.
can you say
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank for help and answers
some people add distinct to every query ... because someone once said it doesn't harm
but it's usually wrong and a performance problem