Hi,
I have a database with a table A with these fields: id, years.
My question is: How I can use this data and populate dropdownlist with unique valies for years. I do not need repeating of years. The same is for months.
Thanks,
Trifon.
Loading
Niradhip ChakrabortyPosted Jun 24, 2009, 1:41 AM
First bind the dropdown list like this.
string strSQL = "";
string strEquipementID = "";
string Datetime = "";
SqlConnection sqlCon = null;
sqlCon = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"].ToString());
SqlCommand sqlCmd = new SqlCommand();
SqlDataAdapter adpData = null;
SqlDataReader sdrData = null;
strSQL = "SELECT * from equipment";
cboDatetime.Items.Clear(); // Id of dropdownlist
cboDatetime.Items.Insert(0, "------- Select -------");
sqlCmd.CommandText = strSQL;
sdrData = sqlCmd.ExecuteReader();
if (sdrData.HasRows)
{
if (sdrData.Read())
{
strEquipementID = sdrData["id "].ToString();
Datetime = sdrData["dtime "].ToString();
cboDatetime.Items.Add(new ListItem(Datetime, strEquipementID));
}
}
sdrData.Close();
Now you have bind the dropdownlist with the daetime value
Use the following code to bind datagrid. Make the autopostback true for the dropdown list and put the following code in selectindexchange event
strSQL = "SELECT * from equipment where id = " + cboDatetime.SelectedValue +" ";
Now get the value in dataset and bind the datagrid
Trifon DinevPosted Jun 23, 2009, 11:02 AM
I have a sql table
create table equipment(
id int not null auto_increment,
dtime timestamp not null,
door char(1) not null,
fire char(1) not null,
temperature char(1) not null
);
I want to use dropdownlist and using dtime (timestamp) to show year, month, day, time, so I can choose what data to be shown in a datagrid. All this depends from dtime field. How can I accomplish this in asp.net c#?
Thanks and regards,
Trifon.
Niradhip ChakrabortyPosted Jun 23, 2009, 1:06 AM
I am not clear about your requirement. Can you please enlighten it little more?
Trifon DinevPosted Jun 22, 2009, 10:03 AM
I used ratadearer - no result.
Dataset and dataadapter - the same result :(((((((((
I want to use : Select anyevent from mydb where year= anyyear and month = anymonth and day in(this, that);
All this from dropdownlists!
Thanks.
Niradhip ChakrabortyPosted Jun 22, 2009, 9:46 AM
You can use the following query.
string strSql ="";
strSql = "select distinct years from table A";