2013-01-31 30 views
0

我試圖用存儲過程與Linq To SQL插入數據。 我沒有收到任何錯誤消息,我的數據也沒有插入。 代碼是在VB中,因爲我也在這個項目中使用XML。Linq存儲過程插入沒有結果

代碼

 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 

我已經做了選擇作品perfekt所以它沒有錯datacontext

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 

謝謝您的幫助

+2

如果你運行SQLProfiler你能看到你的語句執行嗎? – Jodrell

回答

0

檢查這是一個很好的教程:

LINQ to SQL (Updating our Database using Stored Procedures)

此外,檢查test表,如果該值正確插入。

除非另有說明,否則所有系統存儲過程都將返回值0.這表示成功,非零值表示失敗。

RETURN (Transact-SQL)

+0

OP聲明「我的數據沒有被插入。」 – Jodrell

+0

@Jodrell OP也說「當我調試並且它返回0時,我可以進入這個函數」 –

+0

數據不會被插入。 在我的插入返回值是沒有和我的選擇作品的返回值=數據庫查詢(我把它放在一個手錶) 如果我手動執行SP它工作(右鍵單擊它並選擇執行) –

0

你有你的表的主鍵?這是我能夠通過LINQ獲得INSERT/UPDATE/DELETE方法的唯一方法。