Results 1 to 6 of 6

Thread: [RESOLVED] what is wrong with this syntax

  1. #1

    Thread Starter
    Fanatic Member d2005's Avatar
    Join Date
    Aug 2005
    Location
    ireland
    Posts
    620

    Resolved [RESOLVED] what is wrong with this syntax

    Dim sqlcmd As New SqlCommand("sprInsertUser", oSQLConn1)
    sqlcmd.Parameters.Add("@fname", SqlDbType.Char).Value = txtFname.Text
    sqlcmd.Parameters.Add("@town", SqlDbType.Char).Value = txttown.Text
    sqlcmd.Parameters.Add("@carreg", SqlDbType.Char).Value = txtcarreg.Text
    oSQLConn1.Open()
    sqlcmd.ExecuteNonQuery()
    oSQLConn1.Close()

    i get the error
    Incorrect syntax near 'sprInsertUser'.
    it works 60% of the time, all the time.

  2. #2
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: what is wrong with this syntax

    Do you get this on the line ExecuteNonQuery?
    Can you post the SP you are using...well at least the DECLARE bits from the top.
    The param types must match the SP params exactly.

    Woof

  3. #3

    Thread Starter
    Fanatic Member d2005's Avatar
    Join Date
    Aug 2005
    Location
    ireland
    Posts
    620

    Re: what is wrong with this syntax

    ive changed it to this

    VB Code:
    1. oSQLConn1.ConnectionString = "Data Source=(local);" & _
    2.                        "Initial Catalog=StoreProc;" & _
    3.                        "Integrated Security=SSPI"
    4.         strSql = "EXECUTE sprInsertUser"
    5.  
    6.         Dim sqlcmd As New SqlCommand(strSql, oSQLConn1)
    7.         sqlcmd.Parameters.Add("@fname", SqlDbType.Char).Value = txtFname.Text
    8.         sqlcmd.Parameters.Add("@town", SqlDbType.Char).Value = txttown.Text
    9.         sqlcmd.Parameters.Add("@carreg", SqlDbType.Char).Value = txtcarreg.Text
    10.         oSQLConn1.Open()
    11.         sqlcmd.ExecuteNonQuery()
    12.         oSQLConn1.Close()

    but now im on this error

    Procedure 'sprInsertUser' expects parameter '@fname', which was not supplied.

    the SP is

    Code:
    CREATE PROCEDURE sprInsertUser
    ( 
    	@fname char(10),
    	@town char(10),
    	@carreg char(10)
    )
    
     AS
    
    
    
    INSERT INTO tbUser
    (fname, town, carreg)
    VALUES
    (@fname, @town, @carreg)
    GO
    it works 60% of the time, all the time.

  4. #4
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497

    Re: what is wrong with this syntax

    Change the source SQL from
    EXECUTE sprInsertUser
    to
    EXECUTE sprInsertUser @fname, @town, @carreg

    And preserve all the rest of the code you have
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  5. #5

    Thread Starter
    Fanatic Member d2005's Avatar
    Join Date
    Aug 2005
    Location
    ireland
    Posts
    620

    Re: what is wrong with this syntax

    thats the job,
    i spent all day yesterday trying to get that to work, lol
    in this morning checked the thread and 2 seconds job done,

    THANKS

    do you know of any good books for stored procedures and asp.net,
    i think i should get one
    it works 60% of the time, all the time.

  6. #6
    Lively Member {yak}'s Avatar
    Join Date
    Aug 2005
    Posts
    119

    Re: [RESOLVED] what is wrong with this syntax

    You could also set the commandType to StoredProcedure:
    VB Code:
    1. Dim sqlcmd As New SqlCommand("sprInsertUser", oSQLConn1)
    2. sqlcmd.CommandType = CommandType.StoredProcedure
    3. 'ect....
    {yak}

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