Códigos VB.NET

Códigos VB.NET

 

Public Class frmTeste3
    Private cCodigo As Integer

    Public Property Codigo As Integer
        Get
            Return cCodigo
        End Get
        Set(value As Integer)
            cCodigo = value
        End Set
    End Property

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim StringConexao As String
        Dim con As SqlClient.SqlConnection
        Dim da As SqlClient.SqlDataAdapter
        Dim ds As New DataSet
        Dim dr As SqlClient.SqlDataReader
        Dim cmd As SqlClient.SqlCommand
        Dim dt As DataTable
        Dim param As SqlClient.SqlParameter
        Dim sql As String
        Dim Retorno As Integer

        StringConexao = "Data Source=Servidor;Initial Catalog=Banco;User ID=sa;Password=1234"

        '-----------------------------------------------
        con = New SqlClient.SqlConnection(StringConexao)
        con.Open()
        sql = "Select * from Operador_OPR"
        da = New SqlClient.SqlDataAdapter(sql, con)
        da.Fill(ds)
        con.Close()
        DataGridView1.DataSource = ds.Tables(0)

        '-----------------------------------------------
        con = New SqlClient.SqlConnection(StringConexao)
        con.Open()
        sql = "Select * from Operador_OPR"
        cmd = New SqlClient.SqlCommand(sql, con)
        dr = cmd.ExecuteReader()
        While dr.Read
            Debug.Print(dr(0) & " " & dr(1))
        End While
        dr.Close()
        cmd.Dispose()
        con.Close()

        '-----------------------------------------------
        con = New SqlClient.SqlConnection(StringConexao)
        con.Open()
        sql = "update Operador_OPR set Opr_Usuario= 'TESTE2' where Opr_CodUsr = 21"
        cmd = New SqlClient.SqlCommand(sql, con)
        cmd.ExecuteNonQuery()
        cmd.Dispose()
        con.Close()

        '-----------------------------------------------
        con = New SqlClient.SqlConnection(StringConexao)
        con.Open()
        sql = "select count(*) from Operador_OPR"
        cmd = New SqlClient.SqlCommand(sql, con)
        Retorno = cmd.ExecuteScalar()
        cmd.Dispose()
        con.Close()

        '-----------------------------------------------
        con = New SqlClient.SqlConnection(StringConexao)
        con.Open()
        sql = "select * from Operador_OPR"
        cmd = New SqlClient.SqlCommand(sql, con)
        dr = cmd.ExecuteReader()
        dt = dr.GetSchemaTable()
        dr.Close()
        cmd.Dispose()
        con.Close()
        For r = 0 To dt.Rows.Count - 1
            Debug.Print(String.Format("{0} {1} {2}", dt(r)("ColumnName"), dt(r)("DataTypeName"), dt(r)("ColumnSize")))
        Next
        DataGridView1.DataSource = dt

        '-----------------------------------------------
        con = New SqlClient.SqlConnection(StringConexao)
        con.Open()
        sql = "spTeste"
        cmd = New SqlClient.SqlCommand(sql, con)
        cmd.CommandType = CommandType.StoredProcedure
        cmd.Parameters.Add(New SqlClient.SqlParameter("@NomeUsuario", SqlDbType.NVarChar)).Value = "Teste3"
        param = cmd.Parameters.Add(New SqlClient.SqlParameter("@CodigoUsuario", SqlDbType.Int))
        param.Direction = ParameterDirection.Output
        Retorno = param.Value
        cmd.ExecuteNonQuery()
        'CREATE PROCEDURE IncluirUsuario
        '@NomeUsuario Varchar(10)
        'AS
        'Insert into operador_opr (Opr_Usuario) Values (@NomeUsuario)
        'GO()

    End Sub
End Class

RIO DE JANEIRO - RJ - dino@unicodigo.com.br email interno