Software Professional
Very very useful material . Indeed very helpful... Bro.. thanks a lot
(213), (190), (102), (103), (104), (107), (124), (141), (142), (143), (144), (149), (174), (176), (178), (200), (201), (205), (206), (207), (100)
Form1_Load
, set a connection of MySQL Database to Visual Basic 2008. After that, declare all the classes and variables that you needed.
'add reference Imports MySql.Data.MySqlClient Public Class Form1 'set up the string connection of MySQL Database Dim con As MySqlConnection = New MySqlConnection("server=localhost;user id=root;database=employeesdb") 'a set of commands in MySQL Dim cmd As New MySqlCommand 'a Bridge between a database and datatable for retrieving and saving data. Dim da As New MySqlDataAdapter 'a specific table in the database Dim dt As New DataTable Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub End Class
Form1_Load
, declare the variable txt as a TextBox Column and add it in the DataGridView.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'declaring a new textbox column in the datagridview Dim txt As New DataGridViewTextBoxColumn 'adding a textbox column in the datagridview DataGridView1.Columns.Add(txt) End Sub
DataGridView1_ EditingControlShowing
, do the following code for storing data in the TextBox and the autocomplete properties of it.
Private Sub DataGridView1_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing 'declare for a new textbox Dim txt As New TextBox con.Open() 'set a new spicific table in the database dt = New DataTable 'set your commands for holding the data. With cmd .Connection = con .CommandText = "Select * from employees" End With 'filling the table in the database da.SelectCommand = cmd da.Fill(dt) Dim r As DataRow 'represents a row of data in the datatable For Each r In dt.Rows 'get a collection of rows that belongs to this table 'the control shown to the user for editing the selected cell value If TypeOf e.Control Is TextBox Then txt = e.Control 'adding the specific row of the table in the AutoCompleteCustomSource of the textbox txt.AutoCompleteCustomSource.Add(r.Item("EMPLOYEE_ID").ToString) txt.AutoCompleteMode = AutoCompleteMode.Suggest txt.AutoCompleteSource = AutoCompleteSource.CustomSource End If Next 'closing the connection End Sub