ghasem deh

ghasem deh

  • NA
  • 258
  • 37.9k

display dataBase (cells) in listBox

Jan 18 2015 4:45 AM
hi ...
i want display 2 cells from Table (Tsel) in listBox Where Date in record = Today Date 
and use this code :
 
public DataTable SelectData()
{
string selectQuery = "Select Cam From Tsel Where Dat LIKE @d";
SqlCommand Command1 = new SqlCommand(selectQuery, this.con);
Command1.Parameters.AddWithValue("@d", toolStripStatusLabel13.Text);
SqlDataAdapter DataAdapter1 = new SqlDataAdapter(Command1);
try
{
DataTable result = new DataTable();
DataAdapter1.Fill(result);
return result;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return null;
}
finally
{
Command1.Connection.Close();
}
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
this.listBox1.DataSource = this.SelectData();
this.listBox1.DisplayMember = "Cam";
this.listBox1.ValueMember = "Dat";
}
catch
{
}
 
 
butt not happen ! 

Answers (1)