Click here to Skip to main content
15,888,065 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: reading html data using the vb script Pin
Dave Kreskowiak24-Feb-14 17:46
mveDave Kreskowiak24-Feb-14 17:46 
QuestionRunning VB6 programs in Windows 7 Pin
Wycombe24-Feb-14 12:00
Wycombe24-Feb-14 12:00 
AnswerRe: Running VB6 programs in Windows 7 Pin
Dave Kreskowiak24-Feb-14 14:49
mveDave Kreskowiak24-Feb-14 14:49 
GeneralRe: Running VB6 programs in Windows 7 Pin
Wycombe25-Feb-14 5:01
Wycombe25-Feb-14 5:01 
GeneralRe: Running VB6 programs in Windows 7 Pin
Dave Kreskowiak25-Feb-14 6:47
mveDave Kreskowiak25-Feb-14 6:47 
AnswerRe: Running VB6 programs in Windows 7 Pin
MyOwnBoss7-Mar-14 13:02
MyOwnBoss7-Mar-14 13:02 
QuestionMulti Select List box to Word 2007 table Pin
Member 791951624-Feb-14 8:20
Member 791951624-Feb-14 8:20 
QuestionUpdating ComboBox after Insert or Delete with SQL 2008 Pin
Dan O'Riordan23-Feb-14 23:25
Dan O'Riordan23-Feb-14 23:25 
Hello folks,

This issue has me baffled for a few days now. I have tried everything I can possibly think of but nothing seems to work.

In this project, which is just for practice purposes, I insert data to SQL via a small form of three TextBoxes. This works fine and the data is inserted fine. The data is then shown in ComboBox Dropdown where, by selecting a value, shows related content in three other textboxes. This all works fine also.

I can delete content from a third form, which has a DataGridView and by selecting a row and clicking a button, the data is removed from SQL and also the DataGrid updates itself immediately.

The issue I am having is the ComboBox on the main form "Form1" is not updated unless I close the application and reopen it again. I was told on another site that I would need to "Fill the Dataset again". But have no clue what they meant or how that is done.

I tried a few suggestions that I had found on a Google Search but alas, nothing works, such as Form1.Refresh, ComboBox1.Refresh etc.

Here is my code for deleting, which is in the DeleteEntry.vb form:
VB
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim myconnect As New SqlClient.SqlConnection
        myconnect.ConnectionString = "Data Source=.\INFLOWSQL;Initial Catalog=RioDiary;Integrated Security=True"
        Dim mycommand As SqlClient.SqlCommand = New SqlClient.SqlCommand()
        mycommand.Connection = myconnect
        myconnect.Open()


        Try
            mycommand.CommandText = "DELETE FROM MyDiary WHERE Title = @Title"

            'add parameter once
            mycommand.Parameters.Add("@Title", SqlDbType.VarChar)

            For Each row As DataGridViewRow In DataGridView1.SelectedRows
                'set parameter value to Title column of current row
                mycommand.Parameters(0).Value = row.Cells(0).Value

                mycommand.ExecuteNonQuery()
                DataGridView1.Rows.Remove(row)

            Next row

            MsgBox("Data Successfully Deleted")
        Catch ex As System.Data.SqlClient.SqlException
            MsgBox(ex.Message)
        End Try
        ds = New DataSet()
        da.SelectCommand = mycommand
        da.Fill(ds)
        mycommand.Dispose()

        Me.Close()
        myconnect.Close()
    End Sub


And here is Form1:

VB
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'RioDiaryDataSet5.MyDiary' table. You can move, or remove it, as needed.
        Me.MyDiaryTableAdapter.Fill(Me.RioDiaryDataSet5.MyDiary)
        Dim con As New SqlConnection("  Data Source=.\INFLOWSQL;Initial Catalog=RioDiary;Integrated Security=True")
        cmd.CommandText = "Select Title,DiaryContent,DiaryDate FROM MyDiary "
        ComboBox1.Refresh()
        Dim da As New SqlDataAdapter
        da.SelectCommand = cmd
        cmd.Connection = con
        da.Fill(ds, "MyDiary")

        con.Open()

        ComboBox1.DataSource = ds.Tables(0)
        ComboBox1.DisplayMember = "Title"
        ComboBox1.ValueMember = "DiaryContent"
    End Sub

    Private Sub NewEntryToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles NewEntryToolStripMenuItem.Click
        AddEntry.Show()
    End Sub



    Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged

        If (Not Me.ComboBox1.SelectedItem Is Nothing) Then
            Dim SelectedItem = TryCast(ComboBox1.SelectedItem, DataRowView)
            Me.TextBox1.Text = SelectedItem.Row("DiaryDate").ToString()
            Me.TextBox2.Text = SelectedItem.Row("Title").ToString()
            Me.TextBox3.Text = SelectedItem.Row("DiaryContent").ToString()
            ComboBox1.Refresh()
        End If
        con.Close()

    End Sub


Would anyone please help in shedding some light on this? I have been battling my brains and searching google with three days.

Thank you in advance.
AnswerRe: Updating ComboBox after Insert or Delete with SQL 2008 Pin
Eddy Vluggen24-Feb-14 7:53
professionalEddy Vluggen24-Feb-14 7:53 
GeneralRe: Updating ComboBox after Insert or Delete with SQL 2008 Pin
Dan O'Riordan24-Feb-14 18:42
Dan O'Riordan24-Feb-14 18:42 
GeneralRe: Updating ComboBox after Insert or Delete with SQL 2008 Pin
Eddy Vluggen25-Feb-14 0:28
professionalEddy Vluggen25-Feb-14 0:28 
GeneralRe: Updating ComboBox after Insert or Delete with SQL 2008 Pin
Dan O'Riordan25-Feb-14 1:04
Dan O'Riordan25-Feb-14 1:04 
GeneralRe: Updating ComboBox after Insert or Delete with SQL 2008 Pin
Eddy Vluggen25-Feb-14 3:04
professionalEddy Vluggen25-Feb-14 3:04 
GeneralRe: Updating ComboBox after Insert or Delete with SQL 2008 Pin
Dan O'Riordan25-Feb-14 3:29
Dan O'Riordan25-Feb-14 3:29 
QuestionHow do I use ErrorProvider with a bound UserControl? (WinForms) Pin
GroupIII20-Feb-14 17:46
GroupIII20-Feb-14 17:46 
AnswerRe: How do I use ErrorProvider with a bound UserControl? (WinForms) Pin
Eddy Vluggen20-Feb-14 22:30
professionalEddy Vluggen20-Feb-14 22:30 
Question100,000 Items in Check ListBox result in slow performance Pin
Arun Peswani19-Feb-14 7:04
Arun Peswani19-Feb-14 7:04 
AnswerRe: 100,000 Items in Check ListBox result in slow performance Pin
Eddy Vluggen19-Feb-14 8:11
professionalEddy Vluggen19-Feb-14 8:11 
GeneralRe: 100,000 Items in Check ListBox result in slow performance Pin
Arun Peswani19-Feb-14 16:09
Arun Peswani19-Feb-14 16:09 
GeneralRe: 100,000 Items in Check ListBox result in slow performance Pin
Eddy Vluggen20-Feb-14 0:29
professionalEddy Vluggen20-Feb-14 0:29 
GeneralRe: 100,000 Items in Check ListBox result in slow performance Pin
Arun Peswani20-Feb-14 5:35
Arun Peswani20-Feb-14 5:35 
GeneralRe: 100,000 Items in Check ListBox result in slow performance Pin
Eddy Vluggen20-Feb-14 8:45
professionalEddy Vluggen20-Feb-14 8:45 
GeneralRe: 100,000 Items in Check ListBox result in slow performance Pin
Arun Peswani20-Feb-14 20:55
Arun Peswani20-Feb-14 20:55 
GeneralRe: 100,000 Items in Check ListBox result in slow performance Pin
Eddy Vluggen21-Feb-14 6:43
professionalEddy Vluggen21-Feb-14 6:43 
GeneralRe: 100,000 Items in Check ListBox result in slow performance Pin
Arun Peswani22-Feb-14 6:57
Arun Peswani22-Feb-14 6:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.