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
Dim cmd As New SqlCommand
Public Function InsertarDatos(ByVal ClaveAlumno As String, ByVal Nombre As String) As String
cmd = New SqlCommand("Nombre_Procedimiento", cnn)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@ClaveAlumno", SqlDbType.Varchar)
cmd.Parameters.Add("@Nombre", SqlDbType.Varchar)
Try
cmd.ExecuteNonQuery()
Return "Ejecutado Correctamente!"
Catch
Return "Error!"
End Try
End Function
Falta cerrar la conexión.. :)
ps creo que este codigo te puede servir:
Public Class frm
Public conexion As OdbcConnection
Public comando As OdbcCommand
Public sql As String
Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
conexion = New OdbcConnection("dsn=conexión_vb; uid= root; pwd= 123456;")
conexion.Open()
Try
sql = " INSERT INTO docentes VALUES( " & txtid.Text & ",'" & txtnombre.Text & "','" & txtap.Text & "'," & txttel.Text & ");"
comando = New OdbcCommand(sql, conexion)
comando.ExecuteNonQuery()
MsgBox("Los datos han sido guardados correctamente")
Catch ex As Exception
MsgBox(ex.Message)
End Try
txtid.Text = " "
txtnombre.Text = " "
txtap.Text = " "
txttel.Text = " "
txtid.Focus()
End Sub