Conexion de base de datos

Solo disponible en BuenasTareas
  • Páginas : 3 (715 palabras )
  • Descarga(s) : 0
  • Publicado : 14 de junio de 2011
Leer documento completo
Vista previa del texto
Imports System

Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.Sql
'Imports System.Data.DataSet

Public Class Form2

Public Function Insertar(ByVal nomb AsString, _
ByVal compañi As String, _
ByVal sal As String) As Integer

If TotalRegistros(Me.TextBox1.Text) > 0 ThenMsgBox("EL NOMBRE YA EXISTE, NO SE PUEDE REGISTRAR", MsgBoxStyle.OkOnly, "FALLO DE REGISTRO")
Else

Dim cn As New SqlConnection()
cn.ConnectionString = "Data source =monster\sqlexpress;Initial catalog = Examen;Integrated Security = true"

'Dim cn As New SqlConnection("Server = monster/sqlexpress;Database = Examen;Integrated Security = true")' Dim cn As New SqlConnection("data source=monster/sqlexpress;Initial catalog=Examen; Integrated security=True")
'cn.ConnectionString = "data source=monster/sqlexpress;" + _'"Initial catalog=Examen; Integrated security=True"

Dim cmd As New SqlCommand

cmd.CommandText = "INSERT INTO Trabaja " & _
"(persona, compañia,salario) " & _
"VALUES " & _
"(@nomb, @compañi, @sal) "
'"SELECT @@Identity"

cmd.Parameters.Add("@nomb", SqlDbType.NVarChar)cmd.Parameters.Add("@Compañi", SqlDbType.NVarChar)
cmd.Parameters.Add("@sal", SqlDbType.Int)
cmd.Parameters("@nomb").Value = nomb
cmd.Parameters("@Compañi").Value =compañi
cmd.Parameters("@sal").Value = sal
cmd.Connection = cn

Dim t As Integer
Using cn
cn.Open()
t =cmd.ExecuteNonQuery()
If t > 0 Then
MsgBox("SE A INSERTADO CORRECTAMENTE EL REGISTRO", MsgBoxStyle.OkOnly, "AÑADIR")
End If
End Using...
tracking img