|
|
|

|

|
Dicas
|

|
ASP - Active Server Page (Miscelâneas)
|
|
 |
Título da Dica: Usando Command Parameters.Add. Maior Performance para suas Páginas ASP.NET
|
 |
|
|
Postada em 6/10/2003 por ^HEAVY-METAL^
CONECT Imports System.Data Imports System.Data.SqlClient Class genDb Sub ConnectDB() Dim cn as New SqlConnection("server=(local);DataBase=db1;uid=sa;pwd=xuxu") cn.Open() End Sub End Class SELECT , carregando a tabela do SQL Server em um DataTable Imports System.Data Imports System.Data.SqlClient Class genDb Function SelectDB() as DataTable Dim dt as New DataTable Dim cn as New SqlConnection("server=(local);DataBase=db1;uid=sa;pwd=xuxu") Dim sql as String = "Select * From CLIENTES" Dim da as New SqlDataAdapter(sql, cn) da.Fill(dt) Return dt End Function End Class
INSERT , usando SqlCommand e Parameters.Add Imports System.Data Imports System.Data.SqlClient Class genDb Sub insertDB() Dim cn as New SqlConnection("server=(local);DataBase=db1;uid=sa;pwd=xuxu") Dim sql as String sql = "Insert INTO CLIENTES ( " & _ " Nome, " & _ " Endereco, " & _ " Data_Cad, " & _ " CNPJ ) " & _ " Values ( " & _ " @Nome, " & _ " @Endereco, " & _ " @Data_Cad, " & _ " @CNPJ ) " Dim cmd as New sqlCommand(sql, cn) cmd.Parameters.Add("@Nome", SqlDbType.NVarChar, 32).Value = "Joo da Silva" cmd.Parameters.Add("@Endereco", SqlDbType.NVarChar, 32).Value = "Av Paulista, 900" cmd.Parameters.Add("@Data_Cad", SqlDbType.SmallDateTime).Value = System.DateTime.Today() cmd.Parameters.Add("@CNPJ", SqlDbType.Decimal, 18).Value = 12345123000134 cn.Open() cmd.ExecuteNonQuery() cn.Close() End Sub End Class UPDATE , usando SqlCommand e Parameters.Add Imports System.Data Imports System.Data.SqlClient Class genDb Sub updateDB() Dim cn as New SqlConnection("server=(local);DataBase=db1;uid=sa;pwd=xuxu") Dim sql as String sql = "Update CLIENTES SET " & _ " Nome = @Nome, " & _ " Endereco = @Endereco " & _ " Where " & _ " CNPJ = @CNPJ " Dim cmd as New sqlCommand(sql, cn) cmd.Parameters.Add("@Nome", SqlDbType.NVarChar, 32).Value = "Joo da Silva" cmd.Parameters.Add("@Endereco", SqlDbType.NVarChar, 32).Value = "Av Paulista, 900" cmd.Parameters.Add("@CNPJ", SqlDbType.Decimal, 18).Value = 12345123000134 cn.Open() cmd.ExecuteNonQuery() cn.Close() End Sub End Class
T+,
|
|
|
|

|