.net Linq存储过程插入没有结果
我正在尝试使用Linq to SQL的存储过程插入数据。 我没有收到错误消息,也没有插入数据。 代码是用vb编写的,因为我在这个项目中也使用xml 代码 存储过程.net Linq存储过程插入没有结果,.net,vb.net,linq,linq-to-sql,stored-procedures,.net,Vb.net,Linq,Linq To Sql,Stored Procedures,我正在尝试使用Linq to SQL的存储过程插入数据。 我没有收到错误消息,也没有插入数据。 代码是用vb编写的,因为我在这个项目中也使用xml 代码 存储过程 ALTER PROCEDURE testprocedure ( @test varchar(50) ) AS BEGIN INSERT INTO test (testcolum) VALUES (@test) END 当我调试时,我可以看到它进入这个函数,它返回0 <Global.System.Data.Linq.Mapp
ALTER PROCEDURE testprocedure
(
@test varchar(50)
)
AS
BEGIN
INSERT INTO test (testcolum)
VALUES (@test)
END
当我调试时,我可以看到它进入这个函数,它返回0
<Global.System.Data.Linq.Mapping.FunctionAttribute(Name:="dbo.testprocedure")> _
Public Function testprocedure(<Global.System.Data.Linq.Mapping.ParameterAttribute(DbType:="VarChar(50)")> ByVal test As String) As Integer
Dim result As IExecuteResult = Me.ExecuteMethodCall(Me, CType(MethodInfo.GetCurrentMethod,MethodInfo), test)
Return CType(result.ReturnValue,Integer)
End Function
感谢您的帮助检查这本非常好的教程: 此外,如果正确插入值,请检查
测试表
除非另有说明,否则所有系统存储过程都返回值0。这表示成功,非零值表示失败
您的表上有主键吗?这是我能够让INSERT/UPDATE/DELETE方法通过LINQ工作的唯一方法。如果运行SQLProfiler,您可以看到您的语句正在执行吗?OP声明“我的数据没有被插入”。@Jodrell OP还说“我可以确定,当我调试时它将进入此函数,并且返回0”数据没有被插入。在我的insert中,返回值为Nothing,在我的select上,返回值=数据库查询(我在VS中对其进行了监视)如果我手动执行SP,则返回值为Nothing(右键单击并选择execute),我还执行了删除和更新功能,与insert相同。有人知道该方法只选择工作而不选择插入更新删除的原因,我必须做一些错误的事情检查此项:
<Global.System.Data.Linq.Mapping.FunctionAttribute(Name:="dbo.testprocedure")> _
Public Function testprocedure(<Global.System.Data.Linq.Mapping.ParameterAttribute(DbType:="VarChar(50)")> ByVal test As String) As Integer
Dim result As IExecuteResult = Me.ExecuteMethodCall(Me, CType(MethodInfo.GetCurrentMethod,MethodInfo), test)
Return CType(result.ReturnValue,Integer)
End Function
Sub SelectAllBooks()
Dim db As New booksDataContext()
For Each book In db.SelectBooks("Madde")
Dim title = book.title
Dim author = book.author
Dim genre = book.genre
Dim price = book.price
Dim publish_date = book.publish_date
Dim description = book.description
Dim bookid = book.bookid
Console.WriteLine(title & " " & author & " " & genre & " " & price & " " & publish_date & " " & description & " " & bookid)
Next
Console.ReadLine()
End Sub