none
Call a Stored Procedure RRS feed

  • Question

  • Hi, I am using vs 2012, visual basic. I have a stored procedure in mssql, which updates tables with new data. How can I call the stored procedure without returning data. I just want to call it and let it do its work.

    Thursday, April 14, 2016 1:16 PM

Answers

  • Hi rhamill,

    >>Hi, I am using vs 2012, visual basic. I have a stored procedure in mssql, which updates tables with new data. How can I call the stored procedure without returning data. I just want to call it and let it do its work.

    Do you use Linq to SQL, if so, you could use DataContext.ExecuteCommand Method to achieve it. and I create a simple demo for your reference.

    Using db = New DemoContextDataContext()
    		db.ExecuteCommand("InsertIntoOrderInfo {0},{1},{2}", "Test", 11.1, 5)
    		Console.WriteLine("OK")
    		Console.ReadKey()
    	End Using
    

    Store procedure

    CREATE PROCEDURE [dbo].[InsertIntoOrderInfo]
    	@ProductCategory varchar(50) = 'B',
    	@Amount decimal(18,0) = 1.1,
    	@param1 int = 0
    AS
    	insert into OrderInfo values (@ProductCategory, @Amount, @param1)

    Best regards,

    Cole Wu

    Friday, April 15, 2016 1:45 AM
    Moderator

All replies

  • Have you defined the stored procedure in Linq?  If not then drag the procedure to the design workspace for Linq to SQL.  This should create a method with parameters that you can cal.

    Lloyd Sheen

    Thursday, April 14, 2016 2:35 PM
  • Hi rhamill,

    >>Hi, I am using vs 2012, visual basic. I have a stored procedure in mssql, which updates tables with new data. How can I call the stored procedure without returning data. I just want to call it and let it do its work.

    Do you use Linq to SQL, if so, you could use DataContext.ExecuteCommand Method to achieve it. and I create a simple demo for your reference.

    Using db = New DemoContextDataContext()
    		db.ExecuteCommand("InsertIntoOrderInfo {0},{1},{2}", "Test", 11.1, 5)
    		Console.WriteLine("OK")
    		Console.ReadKey()
    	End Using
    

    Store procedure

    CREATE PROCEDURE [dbo].[InsertIntoOrderInfo]
    	@ProductCategory varchar(50) = 'B',
    	@Amount decimal(18,0) = 1.1,
    	@param1 int = 0
    AS
    	insert into OrderInfo values (@ProductCategory, @Amount, @param1)

    Best regards,

    Cole Wu

    Friday, April 15, 2016 1:45 AM
    Moderator