Home>

I'm making windowsform in visualstudio2017.
https://nonbiri-dotnet.blogspot.com/2016/12/blog-post_29.html
The data stored in the database is stored by column specification with reference to.
A program that stores data in the database when the button is pressed

private void button1_Click (object sender, EventArgs e)
        {
            cn.ConnectionString = cnstr;
            cn.Open ();
            cmd.Connection = cn;
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "INSERT INTO [dbo]. [TEXT] VALUES (" +
                               "N '" + textBox2.Text + "')";
            MessageBox.Show ("Saved in database");
            rd = cmd.ExecuteReader ();
            rd.Close ();
            cn.Close ();
            textBox2.Clear ();
        }


Made.
However, the data stored by pressing the button is not stored in combBox.
However, when windowsform is closed and launched, the stored data is stored in combBox.
So please tell me how to add data to combBox when you insert by pressing the button without closing and opening windowsform.

// TODO: This line of code reads data into the 'database1DataSet.TEXT' table.
this.TEXTTableAdapter.Fill (this.database1DataSet.TEXT);

>>Products
Windows Form
>>Search
c # combobox datasource I checked it with the update, but it was not found.
>>Development environment
Visual Sutaudio2017, C # ,. NET Framework4.7, SQL Server Express2017, Windows10

  • Answer # 1

    I imagine you are binding a DataTable named TEXT to a ComboBox, but if that's the case, you won't see the item you added to the ComboBox because the INSERT result is not reflected in the TEXT.

    What happens if I fill and bind again at the end of button1_Click? Note that if you do not clear the contents of TEXT before filling, the item may be double.