Public Conexion As String = "Data Source=.\SQLEXPRESS;Initial Catalog=NombreDeTuBase;Integrated Security=True"
'Public Conexion As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=Construccion.MDF;Integrated Security=True"
Public MiConexion As New SqlConnection(Conexion)
Public Rs As SqlDataReader
Public Com, Insert, Delete As New SqlCommand
Public SQL As String
--------------------------------------------------------------
'INSERTAR
Insert.CommandText = "Insert into ArticuloPorProv(CodProv,CodDetArt,Detalle,Costo,Descuento,CostoXCant)" _
& "Values (" & CodProv & "," & CodArt & "," & IIf(Detalle = "null", Detalle.ToString, "'" & Detalle & "'") _
& "," & Costo & "," & Descuento & "," & CostXCant & ")"
Insert.Connection = MiConexion
Insert.ExecuteNonQuery()
-----------------------------------------------------
'BUSCAR
Sql = "select top 1 CodProv from Proveedores order by 1 desc"
Com = New SqlCommand(SQL, MiConexion)
Rs = Com.ExecuteReader()
Rs.Read()
txtCod.Text = Rs("CodProv") + 1
Rs.Close()
------------------------------------------------
'ACTUALIZAR
Insert.CommandText = "Update Empleados set FechaBaja=null,Baja=0 where CodEmp=" & cod
Insert.Connection = MiConexion
Insert.ExecuteNonQuery()
-----------------------------------------------------
'ELIMINAR
Delete.CommandText = "Update Clientes set Baja=1 where CodCli=" & cod
Delete.Connection = MiConexion
Delete.ExecuteNonQuery()
----------------------------------------------------
Espero se entienda, las variables de conexión y demás estan como públicas porque las mismas se encuentran dentro de un modulo y asi puedo trabajar con ellas desde cualquier parte de mi formulario.
Saludos