locked
[VB 2008] Need help using MonthCalender RRS feed

  • Question

  • I need help making a schedule, any help will be greatly appreciated. I need the users to be able to click a listbox selection and have it refer to a database retrieve the information from the correct table & columns and output the information to select a date on a monthcalender control as well as displaying additional information from the other columns in a textbox.
    Saturday, August 23, 2008 11:57 PM

Answers

  • Take a look at the following code snippet. It bases the combobox selection to issue the query to fetch the data from the database and display the data in the datagridview control. Modify it to based on your scenario. If you have any further issues, feel free to tell us and post the issues with your code snippet.

    Imports System.Data.OleDb
    Public Class Form1
        Dim dt As New DataTable
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=e:\temp\Northwind.mdb")
            Dim sql As OleDbCommand = New OleDbCommand("SELECT ShipperID FROM Shippers", con)
            Dim DataAdapter1 As OleDbDataAdapter = New OleDbDataAdapter()
            DataAdapter1.SelectCommand = Sql
            DataAdapter1.Fill(dt)
        End Sub
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim str() As String
            ReDim str(dt.Rows.Count - 1)
            For i As Integer = 0 To dt.Rows.Count - 1
                str(i) = dt.Rows(i).Item(0).ToString
            Next
            ComboBox1.DataSource = str
        End Sub
        Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
            Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=e:\temp\Northwind.mdb")
            Dim sql As OleDbCommand = New OleDbCommand("SELECT * FROM Shippers WHERE ShipperID= ?", con)
            Dim DataAdapter1 As OleDbDataAdapter = New OleDbDataAdapter()
            Dim dt1 As New DataTable
            DataAdapter1.MissingSchemaAction = MissingSchemaAction.AddWithKey
            sql.Parameters.Clear()
            sql.Parameters.AddWithValue("@id", ComboBox1.Text)
            DataAdapter1.SelectCommand = sql
            DataAdapter1.Fill(dt1)
            DataGridView1.DataSource = dt1
        End Sub
    End Class
    Tuesday, August 26, 2008 1:23 PM
    Moderator