Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Controling forms datasorse through vb
 

Controling forms datasorse through vb

Hi all

I'm working on a form in Access, I have a list box and a calender, I would like to set up the list so that its table query is linked based on the calendar.

When I like on the calendar I would like the list to display only entries that correspond to the months selected in the calendar,

Help would be much appreciated.

G
Gambithunt  Friday, May 25, 2007 2:40 PM

hi Gambithunt

You only implement some deal at the event DateChanged of MonthCalenda control, like the code below

Code Snippet

private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e)
{

int month = int.Parse(monthCalendar1.SelectionStart.Month.ToString());

SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=(local);Initial Catalog=book;Integrated Security=True";
conn.Open();

SqlDataAdapter da = new SqlDataAdapter("select * from bookdetail where publishMonth="+month, conn);

DataTable dt=new DataTable();
da.Fill(ds);

lstBook.Columns.Add("ID");
lstBook.Columns.Add("Name");
lstBook.Columns.Add("Author");

for (int i = 0; i < dt.Rows.Count; i++)
{
ListViewItem item = new ListViewItem();
item.SubItems.Add(dt.Rows[i]["ID"].ToString());
item.SubItems.Add(dt.Rows[i]["Name"].ToString());
item.SubItems.Add(dt.Rows[i]["Author"].ToString());

this.lstBook.Items.Add(item);
}
}

Guang-Ming Bian - MSFT  Thursday, May 31, 2007 9:01 AM

hi Gambithunt

You only implement some deal at the event DateChanged of MonthCalenda control, like the code below

Code Snippet

private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e)
{

int month = int.Parse(monthCalendar1.SelectionStart.Month.ToString());

SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=(local);Initial Catalog=book;Integrated Security=True";
conn.Open();

SqlDataAdapter da = new SqlDataAdapter("select * from bookdetail where publishMonth="+month, conn);

DataTable dt=new DataTable();
da.Fill(ds);

lstBook.Columns.Add("ID");
lstBook.Columns.Add("Name");
lstBook.Columns.Add("Author");

for (int i = 0; i < dt.Rows.Count; i++)
{
ListViewItem item = new ListViewItem();
item.SubItems.Add(dt.Rows[i]["ID"].ToString());
item.SubItems.Add(dt.Rows[i]["Name"].ToString());
item.SubItems.Add(dt.Rows[i]["Author"].ToString());

this.lstBook.Items.Add(item);
}
}

Guang-Ming Bian - MSFT  Thursday, May 31, 2007 9:01 AM

You can use google to search for other answers

Custom Search

More Threads

• Problem with DataGridBoolColumn in the DataGrid
• How to select the parent when a child is selected-Treeview
• Datagrid show few columns...
• Updating datagridview, a few questions.
• Typed DataSet connection
• spurious cell ToolTip shows up when leaving DataGridView before ToolTip can show in cell
• DataGridViewComboBoxColumn Problem
• Best method for binding textboxes to function results from SQL-DB
• The type 'CDMS.CDMSDataSetTableAdapters.TableAdapterManager' has no property named 'tbl_h2TableAdapter'.
• CSV into DataSet