Foro de elhacker.net

Programación => .NET (C#, VB.NET, ASP) => Mensaje iniciado por: Aprendizzz en 23 Marzo 2010, 22:17 pm



Título: necesito de su ayuda en insertar datos en sql 2005 con visual basic.net
Publicado por: Aprendizzz en 23 Marzo 2010, 22:17 pm
Perdonen la molestia soy novato en esto y quisiera que em ayudaran ocn esta funcion por que no inserta los datos para posteriormente guardarlos

 Public Shared Function Insertar(ByVal ClaveAlumno As String, ByVal Nombre As String) As Integer
        Dim cmd As New List(Of SqlClient.SqlParameter)
        cmd.Add(New SqlClient.SqlParameter("@ClaveAlumno", "ClaveAlumno"))
        cmd.Add(New SqlClient.SqlParameter("@Nombre", "Nombre"))
        Dim SP As String
        SP = "insertar"
        Return EjecutaSP(SP, cmd)
    End Function

les dejo mi funcion le deseo lo mejor y gracia spor las respuetas


Título: Re: necesito de su ayuda en insertar datos en sql 2005 con visual basic.net
Publicado por: Shell Root en 23 Marzo 2010, 22:27 pm
Código
  1. Dim cmd As New SqlCommand
  2.  
  3. Public Function InsertarDatos(ByVal ClaveAlumno As String, ByVal Nombre As String) As String
  4.   cmd = New SqlCommand("Nombre_Procedimiento", cnn)
  5.   cmd.CommandType = CommandType.StoredProcedure
  6.   cmd.Parameters.Add("@ClaveAlumno", SqlDbType.Varchar)
  7.   cmd.Parameters.Add("@Nombre", SqlDbType.Varchar)
  8.   Try
  9.      cmd.ExecuteNonQuery()
  10.      Return "Ejecutado Correctamente!"
  11.   Catch
  12.      Return "Error!"
  13.   End Try
  14. End Function


Título: Re: necesito de su ayuda en insertar datos en sql 2005 con visual basic.net
Publicado por: [D4N93R] en 24 Marzo 2010, 15:24 pm
Falta cerrar la conexión.. :)


Título: Re: necesito de su ayuda en insertar datos en sql 2005 con visual basic.net
Publicado por: pauly14 en 18 Marzo 2011, 21:01 pm
ps creo que este codigo te puede servir:
Código
  1. Public Class frm
  2.    Public conexion As OdbcConnection
  3.    Public comando As OdbcCommand
  4.    Public sql As String
  5. Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
  6.        conexion = New OdbcConnection("dsn=conexión_vb; uid= root; pwd= 123456;")
  7.        conexion.Open()
  8.  
  9.        Try
  10.  
  11.            sql = " INSERT INTO docentes VALUES( " & txtid.Text & ",'" & txtnombre.Text & "','" & txtap.Text & "'," & txttel.Text & ");"
  12.            comando = New OdbcCommand(sql, conexion)
  13.            comando.ExecuteNonQuery()
  14.            MsgBox("Los datos han sido guardados correctamente")
  15.        Catch ex As Exception
  16.            MsgBox(ex.Message)
  17.        End Try
  18.        txtid.Text = " "
  19.        txtnombre.Text = " "
  20.        txtap.Text = " "
  21.        txttel.Text = " "
  22.        txtid.Focus()
  23.    End Sub