This code connects to a MySQL database, inserts records into a table, and displays data from that table in a datagrid. It defines a connection string and commands to connect to a MySQL database. Buttons are used to insert new records which are validated, and to load data into a datagrid to display the table contents. The data is loaded from the database into a datatable which is then set as the datasource for the datagrid.
This code connects to a MySQL database, inserts records into a table, and displays data from that table in a datagrid. It defines a connection string and commands to connect to a MySQL database. Buttons are used to insert new records which are validated, and to load data into a datagrid to display the table contents. The data is loaded from the database into a datatable which is then set as the datasource for the datagrid.
This code connects to a MySQL database, inserts records into a table, and displays data from that table in a datagrid. It defines a connection string and commands to connect to a MySQL database. Buttons are used to insert new records which are validated, and to load data into a datagrid to display the table contents. The data is loaded from the database into a datatable which is then set as the datasource for the datagrid.
This code connects to a MySQL database, inserts records into a table, and displays data from that table in a datagrid. It defines a connection string and commands to connect to a MySQL database. Buttons are used to insert new records which are validated, and to load data into a datagrid to display the table contents. The data is loaded from the database into a datatable which is then set as the datasource for the datagrid.
Dim comandosql, cmsq As New MySqlCommand Public mysql_conexion_string As String = "server=10.68.239.21;database=bdsigsm;uid=root;pwd=toor;" Dim bdcon As New MySqlConnection(mysql_conexion_string) Private Sub paneles(ByVal visibilidad As Boolean) For Each c As Control In Me.Controls If TypeOf c Is Panel Then c.Visible = visibilidad End If Next End Sub Private Sub form1_load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load paneles(False) End Sub Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click bdcon.Open() Dim DA = New MySqlDataAdapter("select * from prueba", bdcon) Dim dt As New DataTable DA.Fill(dt) Me.DataGridView1.Visible = True paneles() DataGridView1.DataSource = dt If bdcon.State = ConnectionState.Open Then bdcon.Close() End Sub Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click If Me.TextBox1.Text = "" Or Not IsNumeric(TextBox1.Text) Then MsgBox("Numero esta vacia o el valor no es Entero", MsgBoxStyle.Critical, "Armando Peralta")
ElseIf TextBox2.Text = "" Then
MsgBox("Nombre esta vacio", MsgBoxStyle.Critical, "Alerta") Else bdcon.Open() comandosql = New MySqlCommand("INSERT INTO prueba (campo1,campo2) values (" + TextBox1.Text + ",'" + TextBox2.Text + "')", bdcon) comandosql.ExecuteNonQuery() MsgBox("Proceso OK", MsgBoxStyle.Information, "Insertar Registros") If bdcon.State = ConnectionState.Open Then bdcon.Close() Me.TextBox1.Text = Nothing Me.TextBox2.Text = Nothing