How to save vb.net combobox content into mysql table?


Problem :

I have an issue here .. i cant save combobox content into my table ... all other data are successfully saved but the combo box is saved either 1 or zero .. what seems to be wrong?

My tables are designed through navicat .. does this have anything to do with my choice of data type? knowing that I chose the data type to be Text

This is my code and it shows no run errors

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim conStr As String = ("Data Source=localhost;user id=root;password=123456;database=sam;")
        Try
            Dim con As New MySqlConnection(conStr)
            Dim cmd As MySqlCommand

            For i = 0 To ComboBox4.Items.Count
                con.Open()

                Dim sqls As String = "INSERT INTO initial_nom(f_name,s_name,th_name,fo_name,app_no,adm_type) VALUES('" & TextBox1.Text & "', '" & TextBox2.Text & "', '" & TextBox3.Text & "', '" & TextBox4.Text & "'," & TextBox5.Text & ",'" & ComboBox4.SelectedIndex.ToString & "')"
                cmd = New MySqlCommand(sqls, con)
                cmd.ExecuteNonQuery()
            Next
        Catch ex As Exception
            MsgBox("Error in saving to Database. Error is :" & ex.Message)
        End Try
    End Sub


Solution :

SelectedIndex is integer which point to index of the selected item. Assuming that combobox's data source contains collection of string, try to use SelectedItem instead, type-cast it to string :

DirectCast(ComboBox4.SelectedItem, String)

Mysql Tutorials

Mysql Howto..

mySQL: how to fill this questions - answers table

how to get number of days between consecutive records in table?

How do I handle MySQL to Javascript Date Format?

PHP - How to use GeoLite2 IP CSV databases in MySql?

How can I get MySQL to work on OSX?

How to run a big update on a live database?

How to compare elapsed time between datetime fields?

How to export data into a word document, not the SQL Query? VB.NET

How to get number of rows without SELECTING all rows?

How can I use PHP to delete all records in a MySQL database?

how to find the max of a field and group by one field in mysql

How to insert in MYSQL different data for same ID

How can I enable the user to enter reserved characters into the database with a combination of PHP, MySQL and AJAX?

How to use own function to replace array element in array returned from MySQL

How can I iterate through a MySQL result set?

How to parse csv file into mysql DB with PHP with conditions

how to Search multiple columns of a table in MySQL?

How to get random id's

how to show login username in php

How to fetch and print utf-8 data from mysql DB using Python?

How to filter the rows by points. PHP/MySQL

MySQL how to get the time difference, if second argument is NULL by using TIMESTAMPDIFF?

How do I cast ENUMs to their integer values when selecting into an outfile in MySQL?

How to order, group, order with mySQL

How to store “key => value” pairs as strings for future parsing?

MySQL: How to find the homewrecker by counting *each* group by subsection?

How to order data randomly

How do you migrate Amazon RDS from MySQL 5.1 to MySQL 5.5?

How could I change this mysql to mysqli?

How to select by condition on JSON column in MySQL?