我试图用 Linq To SQL 的存储过程插入数据。我没有收到错误消息,并且我的数据没有被插入。代码在 vb 中,因为我也在这个项目中使用 xml。
代码
Using db As New booksDataContext()
db.testprocedure("kkk")
db.SubmitChanges()
End Using
存储过程
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
我已经完成了一个可以完美运行的 Select,因此它的数据上下文没有错
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
谢谢您的帮助