【发布时间】:2013-01-31 10:56:46
【问题描述】:
我正在尝试使用 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
我已经做了一个完美的选择,所以它的数据上下文没有错
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
感谢您的帮助
【问题讨论】:
-
如果你运行 SQLProfiler,你能看到你的语句被执行了吗?
标签: .net vb.net linq linq-to-sql stored-procedures