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

"Cadena de Coneccion": Imports Imports Public Class Dim As New Dim As New

This code defines a class that connects to a SQL database and retrieves data from a table. It contains: 1) A SqlConnection object and SqlCommand object that are used to connect to the database and execute commands. 2) An event handler that is called when the form loads to initialize the connection and command objects. 3) An event handler for a button click that uses a SqlDataAdapter to fill a DataSet with data retrieved from a SELECT query, and sets this as the data source for a dropdown list control.

Uploaded by

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

"Cadena de Coneccion": Imports Imports Public Class Dim As New Dim As New

This code defines a class that connects to a SQL database and retrieves data from a table. It contains: 1) A SqlConnection object and SqlCommand object that are used to connect to the database and execute commands. 2) An event handler that is called when the form loads to initialize the connection and command objects. 3) An event handler for a button click that uses a SqlDataAdapter to fill a DataSet with data retrieved from a SELECT query, and sets this as the data source for a dropdown list control.

Uploaded by

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

Imports System.

Data
Imports System.Data.SqlClient
Public Class Form1
Dim con As New SqlConnection("cadena de coneccion"
Dim cmd As New SqlCommand
Pri!ate Sub Form1"#oad($y%al sender As &b'ect( $y%al e As System.)!entAr*s +andles ,e.#oad
-ry
cmd.Command-ype . Command-ype.-e/t
cmd.Connection . con
Catc0 e/ As Sql)/ception
,essa*e$o/.S0ow(")11&12 " 3 e/.,essa*e
Catc0 e/ As )/ception
,essa*e$o/.S0ow(")11&12 " 3 e/.,essa*e
)nd -ry
)nd Sub
Pri!ate Sub $tn4enerar"Clic5($y%al sender As System.&b'ect( $y%al e As System.)!entAr*s +andles $tn4enerar.Clic5
Dim daDatosS6# As New SqlDataAdapter(
Dim dsDatosS6# As New DataSet(
-ry
cmd.Command-e/t . " select 7 8rom tbcarro "
con.&pen(
daDatosS6# . New SqlDataAdapter(cmd
dsDatosS6# . New DataSet(
daDatosS6#.Fill(dsDatosS6#
4!Select.DataSource . dsDatosS6#.-ables(9
con.Close(
Catc0 e/ As Sql)/ception
,essa*e$o/.S0ow(")11&12 " 3 e/.,essa*e
Catc0 e/ As )/ception
,essa*e$o/.S0ow(")11&12 " 3 e/.,essa*e
Finally
I8 con.State . ConnectionState.&pen -0en
con.Close(
)nd I8
)nd -ry
)nd Sub
)nd Class

You might also like