0% found this document useful (0 votes)
15 views2 pages

Conexión VB A SQL Server

This document contains code examples for connecting to SQL Server and MySQL databases from VB.NET. It shows how to create SqlConnection and MySqlConnection objects to connect to databases, open the connections, execute simple queries, and display messages on successful or failed connections. It also demonstrates loading data from a SQL query into a DataTable and binding that to a data grid view control.

Uploaded by

Diego Jara
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views2 pages

Conexión VB A SQL Server

This document contains code examples for connecting to SQL Server and MySQL databases from VB.NET. It shows how to create SqlConnection and MySqlConnection objects to connect to databases, open the connections, execute simple queries, and display messages on successful or failed connections. It also demonstrates loading data from a SQL query into a DataTable and binding that to a data grid view control.

Uploaded by

Diego Jara
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Conexión VB a SQL server

Imports System.Data.SqlClient

Public Class Form1


Private con As SqlConnection
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
Try
con = New SqlConnection("database=Peru;data source=.;integrated
security=true")
con.Open()
MessageBox.Show("Mi Primera vez ", "Yeah")
con.Close()
Catch ex As Exception
MessageBox.Show("No se pudo conectar ")

End Try
End Sub
End Class

Conectar VB SQL y MYSQL

Imports System.Data.SqlClient
Imports MySql.Data.MySqlClient

Public Class Form1


Private conmy As MySqlConnection
Private con As SqlConnection
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
Try
con = New SqlConnection("database=Peru;data source=.;integrated
security=true")
con.Open()
MessageBox.Show("Mi Primera vez sql", "Yeah")
con.Close()
Catch ex As Exception
MessageBox.Show("No se pudo conectar ")

End Try
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles


Button2.Click
Try
conmy = New MySqlConnection("database=rusia;data source=localhost;user
=root")
conmy.Open()
MessageBox.Show("Mi Primera vez Mysql ", "Yeah")
Catch ex As Exception
MessageBox.Show("No se pudo conectar ")
End Try
End Sub
End Class
DT a sql

con = new SqlConnection("database=Peru;data source=.;integrated security=true");

con.Open();
string ape = txtape.Text;
string sql = " select * from cliente where nom_cli like '" + ape + "%'";
SqlDataAdapter da = new SqlDataAdapter(sql, con);
DataTable dt = new DataTable ();
da.Fill(dt);
dgvdato.DataSource = dt;
con.Close();

You might also like