Results 1 to 4 of 4

Thread: Creating stored procs with VB.NET

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2005
    Posts
    40

    Creating stored procs with VB.NET

    I have to create databases and stored procs based on a user's prompt through a web page.

    Is there a way to create a stored proc within VB.NET?

    Thanks,
    Ninel

  2. #2

    Thread Starter
    Member
    Join Date
    Mar 2005
    Posts
    40

    Re: Creating stored procs with VB.NET

    I need to create a stored procedure that has quite a few statements.
    Code:
    CREATE PROCEDURE usp_PoliticalProcessing 
    AS
    
    UPDATE dbo.list_staging 
    SET sPhone = RTrim(LTrim(Convert(varchar(30), Convert(numeric(20, 1), phone))))
    
    UPDATE dbo.list_staging 
    SET sPhone = Substring(sphone, 1, patindex('%.%', sphone)-1)
    
    UPDATE  dbo.list_staging 
    SET  sphone =  replace(replace(replace(replace(replace(replace(sphone,'.',''),',',''  ),'-',''), ' ',''), '(', ''), ')', '')
    
    ALTER TABLE  dbo.list_staging  ADD [iList_StagingID] INT IDENTITY(1,1)
    
    ALTER TABLE  dbo.list_staging  ADD [sFailedValidation] char(1)
    
    Update dbo.list_staging
    SET sFailedValidation = 'X' 
    WHERE(Len(RTrim(LTrim(sPhone))) <> 10)"
    
    UPDATE a "
    SET a.sFailedValidation = 'X' "
    FROM  dbo.list_staging a "
    INNER JOIN   dbo.list_staging b "
    ON a.sPhone= b.sPhone "
    WHERE(a.iList_StagingID > b.iList_StagingID)
    I did some research and found that SQL Server doesn't allow statements to be combined in one batch. (You can combine them when using the GO keyword and executing from SQL Query Analyzer or another tool, but not from within code.)

    Having said all that, how can I create this proc from within VB.NET?

    Is this even possible?

    Thanks,
    Ninel

  3. #3
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Creating stored procs with VB.NET

    Have you tried executing a SQL string with all that in it?

    It should work.

    GO is a keyword that QA recognizes to break up a batch - not to break up multiple lines.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Creating stored procs with VB.NET

    Start here:
    http://davidhayden.com/blog/dave/arc...3/27/2890.aspx


    scroll down to the SQL Server Management Objects section.... links to tutorials there. The code samples are in C#, but it doesn't take much to convert them to VB.NET.


    -tg
    OG Tay sez: dude.
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width