Error converting data type varchar to numeric - stored procedures

Discussion in 'ASP .Net' started by luna, Feb 6, 2004.

  1. luna

    luna Guest

    got so far then it broke and i cant get it working again - it was updating
    fine but not inserting and now im getting a "Error converting data type
    varchar to numeric" which i didnt have before....

    stored procedure is

    CREATE Procedure newupdate

    @newid varchar(50),
    @newnews varchar(50)

    AS

    IF EXISTS (SELECT * FROM dbo.news WHERE ID =@newid)

    UPDATE dbo.news SET news = @newnews WHERE Id =@newid

    ELSE

    INSERT into dbo.news (news) VALUES ("@newnews")
    GO

    which parses fine - so im guessing its the asp side of things

    which is

    Dim newid As String = TextBox1.Text.ToString
    Dim newnews As String = TextBox2.Text.ToString

    Dim strConn As String = "server=;uid=sa;pwd=;database=news"
    Dim conn As New System.Data.SqlClient.SqlConnection(strConn)
    Dim sql As String = "newupdate '" & newnews & "', '" & newid &
    "'"

    Dim Cmd As New System.Data.SqlClient.SqlCommand(sql, conn)
    Dim objDR As System.Data.SqlClient.SqlDataReader
    conn.Open()
    objDR =
    Cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
    'Cmd.ExecuteNonQuery()

    conn.Close()

    to me this should work!!!!
    luna, Feb 6, 2004
    #1
    1. Advertising

  2. Apparently the "Id" column in your database is not a varchar field...

    --
    HTH,
    Kevin Spencer
    ..Net Developer
    Microsoft MVP
    Big things are made up
    of lots of little things.

    "luna" <> wrote in message
    news:8fLUb.148$...
    > got so far then it broke and i cant get it working again - it was updating
    > fine but not inserting and now im getting a "Error converting data type
    > varchar to numeric" which i didnt have before....
    >
    > stored procedure is
    >
    > CREATE Procedure newupdate
    >
    > @newid varchar(50),
    > @newnews varchar(50)
    >
    > AS
    >
    > IF EXISTS (SELECT * FROM dbo.news WHERE ID =@newid)
    >
    > UPDATE dbo.news SET news = @newnews WHERE Id =@newid
    >
    > ELSE
    >
    > INSERT into dbo.news (news) VALUES ("@newnews")
    > GO
    >
    > which parses fine - so im guessing its the asp side of things
    >
    > which is
    >
    > Dim newid As String = TextBox1.Text.ToString
    > Dim newnews As String = TextBox2.Text.ToString
    >
    > Dim strConn As String = "server=;uid=sa;pwd=;database=news"
    > Dim conn As New System.Data.SqlClient.SqlConnection(strConn)
    > Dim sql As String = "newupdate '" & newnews & "', '" & newid &
    > "'"
    >
    > Dim Cmd As New System.Data.SqlClient.SqlCommand(sql, conn)
    > Dim objDR As System.Data.SqlClient.SqlDataReader
    > conn.Open()
    > objDR =
    > Cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
    > 'Cmd.ExecuteNonQuery()
    >
    > conn.Close()
    >
    > to me this should work!!!!
    >
    >
    >
    Kevin Spencer, Feb 6, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Maziar Aflatoun

    Returning a varchar from a stored procedure

    Maziar Aflatoun, Apr 22, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    14,676
    Maziar Aflatoun
    Apr 22, 2005
  2. dew
    Replies:
    3
    Views:
    4,540
    Alejandro Penate-Diaz
    Feb 9, 2006
  3. Elmo Watson
    Replies:
    0
    Views:
    2,930
    Elmo Watson
    Mar 29, 2006
  4. darrel
    Replies:
    4
    Views:
    785
    darrel
    Jul 19, 2007
  5. jcpc
    Replies:
    2
    Views:
    1,445
Loading...

Share This Page