logo
down
shadow

Inserting combo box values?


Inserting combo box values?

By : Rajneesh
Date : November 19 2020, 03:59 PM
will be helpful for those in need I'm trying to get my system to insert combo box values into my access database. I always get this very long error whenever I try to click my 'add' button and I somehow get this feeling that it's because of my INSERT statement. This is my whole code for my form. Any help will be greatly appreciated! Thank you , You need to change your query in this way
code :
Private Sub btnAdd_Click(sender As System.Object, e As System.EventArgs) Handles btnAdd.Click
    Dim rbdtext As String = cboyr.SelectedItem.ToString
    Dim uno As String = cbosec.SelectedItem.ToString

    Try
        Dim cnString = = "Provider=Microsoft.ACE.OLEDB.12.0;" & _ 
                         "Data Source=C:\Thesis\Thesis\Database1.accdb"
        Dim sqlquery As String = "INSERT INTO students " & _
            "(StudentID, FirstName,MiddleName,LastName,Yr, [Section]) " & _
            "VALUES (@studid, @fname,@mname,@lname,@yr, @sec)"

        ' Use this form to initialize both connection and command to 
        ' avoid forgetting to set the appropriate properties....

        Using conn = New System.Data.OleDb.OleDbConnection(cnString)
        Using cmd = New System.Data.OleDb.OleDbCommand(sqlQuery, conn)

            conn.Open()
            cmd.Parameters.AddWithValue("@studid", TxtID.Text)
            cmd.Parameters.AddWithValue("@fname", txtFName.Text)
            cmd.Parameters.AddWithValue("@mname", txtMName.Text)
            cmd.Parameters.AddWithValue("@lname", txtLName.Text)
            cmd.Parameters.AddWithValue("@yr", rbdtext)
            cmd.Parameters.AddWithValue("@sec", uno)

            Dim rowsInserted = cmd.ExecuteNonQuery()
            if rowsInserted > 0 Then
                MessageBox.Show("One record successfully added!", "Added!")
            else
                MessageBox.Show("Failure to add new record!", "Failure!")
            End if
        End Using
        End Using
    Catch ex As Exception
        MessageBox.Show("Error: " & ex.Message)
    End Try


Share : facebook icon twitter icon
Change values in combo box by selection in first combo box

Change values in combo box by selection in first combo box


By : Jijie Xue
Date : March 29 2020, 07:55 AM
Hope this helps I've got some code like the following. I want it so that when I chose an item in 'select 1' it changes the in the second combo box but I'm not sure of the best way to go about it. Does it have to be AJax or can it be done with just Javascript? , Here:
code :
<html>
    <head>
        <!-- Connect jQuery from Google library storage -->
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
    </head>
    <body>
        <!-- Create select for class, with id #class -->
        <select id="class" name="class">
            <option value="0">Econom</option>
            <option value="1">Business</option>
            <option value="2">First</option>
        </select>
        <!-- Create select for place, with id #place -->
        <select id="place" name="place" disabled="disabled"></select>
        <!-- Create view place for price, with id #price -->
        <span id="price"></span>
        <script type="text/javascript">
            // available places to choose 
            var available = {
                0:      {
                    25: 50
                },
                1:      {
                    26: 100
                },
                2:      {
                    21: 200,
                },
            }

            // When the document is totally loaded, do that things that's defined in function(e) {}
            $(document).ready(function(e){
                // Bind trigger for class select changing, where $('select#class') - find element that in DOM select inputs and has id="class"
                // When it change, call function(e) {}, inside this function $(this) will be the select itself
                $('select#class').live('change', function(e){
                    // find place select input
                    var place = $('select#place');
                    // if it's disabled, unblock it, and clean all options inside
                    place.removeAttr('disabled').find('option').remove();
                    // foreach places in available create option and put it into place select
                    for (var i in available[$(this).val()]) {
                        place.append($('<option />').val(i).html(i));
                    }
                    // behave like place select have changed, and trigger listener above
                    place.change();
                });

                $('select#place').live('change', function(e){
                    $('span#price').html(available[$('select#class').val()][$(this).val()]);
                });
            });
        </script>
    </body>
</html>
Unable to Move the List of values from Right Combo bx to Left Combo bx (Multiple List of values)

Unable to Move the List of values from Right Combo bx to Left Combo bx (Multiple List of values)


By : Shaun Fyffe
Date : March 29 2020, 07:55 AM
With these it helps try removing count--; from your code I have a feeling this is preventing the loop from moving onto the next iteration if it finds a selected item in the list.
seems to work fine to me:
C# Windows Forms how to change values of second combo box based on selection in first combo box

C# Windows Forms how to change values of second combo box based on selection in first combo box


By : VivaLaTexas
Date : March 29 2020, 07:55 AM
it helps some times You could just populate the sizeBox collection directly from the itemBox selected change event handler and remove sizeBox_SelectedIndexChanged altogether.
However, to achieve what, you need to clear the items in the sizeBox once the item has been selected. You can achieve this via:
code :
sizeBox.Items.Clear();
sizeBox.Items.Add("New Size");
only show the updated values in combo box after another combo box selection

only show the updated values in combo box after another combo box selection


By : oleggen
Date : March 29 2020, 07:55 AM
may help you . You should remove the item at the selectedindex from the Items collection of the first combo.
Notice that I have also changed your code to use the correct using statement around disposable objects and a parameter instead of your very dangerous string concatenation
code :
private void cb_oname_SelectedIndexChanged(object sender, EventArgs e)
{
    // Safety check, SelectedIndexChanged is called also when there is
    // no item selected (see later)
    if(cb_oname.SelectedIndex < 0)
        return;

    using(SqlConnection sqlConnection = new SqlConnection(.....))
    using(SqlCommand sqlCmd2 = new SqlCommand(@"SELECT Product_category 
                     FROM Product2 WHERE Product_Name=@name", sqlConnection))
    {
        sqlConnection.Open();
        sqlCmd2.Parameters.Add("@name", SqlDbType.NVarChar).Value = cb_oname.SelectedItem;

        using(SqlDataReader sqlrdr = sqlCmd2.ExecuteReader())
        {
            // Clear the previous items list
            cb_ocat.Items.Clear(); 
            while (sqlrdr.Read())
                cb_ocat.Items.Add(sqlrdr["Product_category"].ToString());
        }
    }
    // Remove from the Items collection, but it is not enough
    cb_oname.Items.RemoveAt(cb_oname.SelectedIndex);
    // Set the selectedindex to -1 so the current text in the combo is reset        
    cb_oname.SelectedIndex = -1;
}
Arrow key selection does not work to Autocompleated combo box when combo box values are reload java Fx

Arrow key selection does not work to Autocompleated combo box when combo box values are reload java Fx


By : user1614056
Date : March 29 2020, 07:55 AM
it should still fix some issue I believe this issue occurs due to the several overlapping AutoCompletionBindings. In order to fix that you should keep reference to the previous binding and dispose it upon reload. Also, note that to clear the selection in JavaFX combobox more steps should be performed.
code :
private AutoCompletionBinding<String> completion;
....
private void loadValuesToComboSearchBox() {
    try {
        // clear selection
        comboSearch.getItems().clear();
        comboSearch.valueProperty().set(null);
        comboSearch.getEditor().clear();

        comboSearch.setEditable(false);
        ResultSet getSearchElements = employeDao.getSearchemployeeByNicFnameLnmeId();
        Set<String> addElements = new LinkedHashSet<>();
        while (getSearchElements.next()) {
            addElements.add(getSearchElements.getString("id"));
            addElements.add(getSearchElements.getString("firstname"));
            addElements.add(getSearchElements.getString("lastname"));
            addElements.add(getSearchElements.getString("nic"));
        }

        if (completion != null) {
            completion.dispose();
        }
        completion = TextFields.bindAutoCompletion(comboSearch.getEditor(), addElements);
        comboSearch.setEditable(true);
    } catch (Exception e) {
        new Alert(Alert.AlertType.INFORMATION, e + "", ButtonType.OK).showAndWait();
        e.printStackTrace();
    }
}
Related Posts Related Posts :
  • VB.NET | Get current user profile folder
  • How to create a folder and a file in my project root directory
  • Testing if I have full read/write access to a file in VB .NET 4.5 before processing it
  • how to refresh my datagridview after I add new data
  • How to get Motherboard name in VB.net?
  • Loop Through LINQ Results
  • How do I remove this GoTo?
  • Display image in DataGridView not working properly
  • How can limit how many times an operator shows up in my maths quiz in vb?
  • Expression Lambda to order fields with null value
  • DevExpress Add items to ComboBox at run time
  • GetManifestResourceStream in module
  • Save and open vbs script programmatically
  • Option Strict On, set Focus of unknown object type
  • Google API No application is associated with the specified file for this operation
  • Converting items in listview too string. VB
  • Mouse position at end of textbox on Mouse Click event
  • Run or Embed VB.NET console application within a VB.NET or C# forms application
  • Getting error while running the query
  • DevExpress GridView FocusedRowHandle Does not update on right click
  • Local RDLC report using spatial data
  • vb.net database query and checkbox , proper way to do?
  • Why error ???? Syntax error in INSERT INTO statement
  • string.IsNullOrEmpty vs string = '' in Visual Basic
  • Execute a subroutine before exiting the application
  • comparing two dates at midnight in vb never match
  • DataSource No Longer Fills Data Calls VB 2010
  • Check if todays is first weekday of month?
  • VB.NET - LINQ - dbContext - Where - Letter is not declared error. Trying to update single record
  • What is the equivalent of FirstSibling in .NET XMLNode?
  • Get value of one columns in DataGridView with multi select vb.net
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org