Hola, tengo problemas al insertar en una BD SQL Server
2000, desde ADO.NET, lo hago desde un .vb, y los SELECT
funcionan bien, pero cuando quiero hacer un INSERT ya sea
con StoreProcedures o con sentencias ad-hoc,
sencillamente no lo hace. Aqui esta el código del
StoreProcedure:
**********************************************************
CREATE PROCEDURE SP_CustomerAdd
(
@customerIdInput int,
@customerName nvarchar(20),
@customerEmail nvarchar(20),
@customerPassword nvarchar(20),
)
AS
INSERT INTO customers
(
customerId,
customerName,
customerEmail,
customerPassword
)
VALUES
(
@customerIdInput,
@customerName,
@customerEmail,
@customerPassword
)
GO
**********************************************************
Y aqui, el codigo del archivo .vb, es un metodo que lo
llamo desde la página .aspx, en el boton_Click.
**********************************************************
Public Function AddCustomer(customerName As String,
customerEmail As String, customerPassword As String) As
String
'Crear instancia de los objetos Connection y Command
Dim myConnection As SqlConnection = New SqlConnection
(ConfigurationSettings.AppSettings("connex"))
Dim myCommand As New SqlCommand("SP_CustomerAdd",
myConnection)
myCommand.CommandType = CommandType.StoredProcedure
'Cuenta la cantidad de registros en la tabla "customers"
'Algoritmo para asignarle un consecutivo de ID al cliente
Dim customerAutoId As Integer
Dim contCustomers As Integer
Dim dsCont As New DataSet()
Dim dataRowCont As DataRow
Dim dsMax As New DataSet()
Dim dataRowMax As DataRow
Dim daCont As New SqlDataAdapter("SELECT COUNT
(customerId) AS COUNT FROM customers", myConnection)
daCont.Fill(dsCont, "COUNT")
For Each dataRowCont in dsCont.Tables("COUNT").Rows
contCustomers = CInt(dataRowCont("COUNT").ToString() - 1)
Next
If contCustomers > 0 Then
Dim daMax As New SqlDataAdapter("SELECT MAX(customerId)
AS MAX FROM customers", myConnection)
daMax.Fill(dsMax, "MAX")
For Each dataRowMax in dsMax.Tables("MAX").Rows
customerAutoId = CInt(dataRowMax("MAX").ToString() + 1)
Next
Else
customerAutoId = 1
End If
Return CStr(customerAutoId)
'Agregar parámetros al SPROC
Dim parameterCustomerIdInto As New SqlParameter
("@customerIdInput", SqlDbType.Int)
parameterCustomerIdInto.Direction =
ParameterDirection.Input
parameterCustomerIdInto.Value = customerAutoId
myCommand.Parameters.Add (parameterCustomerIdInto)
Dim parameterCustomerName As New SqlParameter
("@customerName", SqlDbType.NVarChar)
parameterCustomerName.Direction = ParameterDirection.Input
parameterCustomerName.Value = customerName
myCommand.Parameters.Add (parameterCustomerName)
Dim parameterCustomerEmail As New SqlParameter
("@customerEmail", SqlDbType.NVarChar)
parameterCustomerEmail.Direction =
ParameterDirection.Input
parameterCustomerEmail.Value = customerEmail
myCommand.Parameters.Add (parameterCustomerEmail)
Dim parameterCustomerPassword As New SqlParameter
("@customerPassword", SqlDbType.NVarChar)
parameterCustomerPassword.Direction =
ParameterDirection.Input
parameterCustomerPassword.Value = customerPassword
myCommand.Parameters.Add (parameterCustomerPassword)
Try
myConnection.Open()
myCommand.ExecuteNonQuery()
myConnection.Close()
Catch
Return String.Empty
End Try
End Function
**********************************************************
Si alguien pudiera ayudarme, estaria muy agradecida.
Leer las respuestas