Home All Groups Group Topic Archive Search About

Update Command with Parameter....

Author
14 Apr 2005 9:29 AM
A_PK
Could anyone pls guide me what is wrong with my Update Command

        Dim signbyte As Byte()
        signbyte = GetByteArray() ' i create this function to return
ByteArray

        Try
            Dim cmd As New SqlCeCommand
            cmd.Connection = myConnection

            ' Someone give me the following insert statement....this ?
parameter is working,
            'but I modify to update statement with @ or ?, both not
working....
            'cmd.CommandText = "insert into test (picture) values (?)"

            cmd.CommandText = "UPDATE bm00ts0001 SET imgarray = ? WHERE tid
= '" & vartid & "'"
            Dim param As SqlCeParameter = cmd.Parameters.Add("imgarray",
SqlDbType.Image)
            param.Value = signbyte
            myConnection.Open()
            cmd.ExecuteNonQuery()
            myConnection.Close()

        Catch sqex As SqlCeException
            MessageBox.Show(sqex.ToString(), "DB operation failed")
        Catch er As Exception
            MessageBox.Show(er.ToString)
        End Try

Author
14 Apr 2005 10:27 AM
Larry Lard
A_PK wrote:
Show quoteHide quote
> Could anyone pls guide me what is wrong with my Update Command
>
>         Dim signbyte As Byte()
>         signbyte = GetByteArray() ' i create this function to return
> ByteArray
>
>         Try
>             Dim cmd As New SqlCeCommand
>             cmd.Connection = myConnection
>
>             ' Someone give me the following insert statement....this
?
> parameter is working,
>             'but I modify to update statement with @ or ?, both not
> working....
>             'cmd.CommandText = "insert into test (picture) values
(?)"
>
>             cmd.CommandText = "UPDATE bm00ts0001 SET imgarray = ?
WHERE tid
> = '" & vartid & "'"
>             Dim param As SqlCeParameter =
cmd.Parameters.Add("imgarray",
> SqlDbType.Image)
>             param.Value = signbyte
>             myConnection.Open()
>             cmd.ExecuteNonQuery()
>             myConnection.Close()
>
>         Catch sqex As SqlCeException
>             MessageBox.Show(sqex.ToString(), "DB operation failed")
>         Catch er As Exception
>             MessageBox.Show(er.ToString)
>         End Try


I've always been told that the ? syntax for parameters is an ODBC
thing; when using a direct SQL connection you should use the @name
parameter style. Try the following changes:

Change
cmd.CommandText = "UPDATE bm00ts0001 SET imgarray = ? WHERE tid = '" &
vartid & "'"
To
cmd.CommandText = "UPDATE bm00ts0001 SET imgarray = @imgarray WHERE tid
= '" & vartid & "'"

Change
Dim param As SqlCeParameter = cmd.Parameters.Add("imgarray",
SqlDbType.Image)
To
Dim param As SqlCeParameter = cmd.Parameters.Add("@imgarray",
SqlDbType.Image)

Making these changes meant this code worked for me on a normal (not CE)
SQL Server.

--
Larry Lard
Replies to group please
Author
15 Apr 2005 12:41 AM
A_PK
Hi ....I tried the following code u gave me...i am expericing Token Line
Error ...what the problem could be ?


Show quoteHide quote
"Larry Lard" <larryl***@hotmail.com> wrote in message
news:1113474429.213146.101970@z14g2000cwz.googlegroups.com...
>  A_PK wrote:
>> Could anyone pls guide me what is wrong with my Update Command
>>
>>         Dim signbyte As Byte()
>>         signbyte = GetByteArray() ' i create this function to return
>> ByteArray
>>
>>         Try
>>             Dim cmd As New SqlCeCommand
>>             cmd.Connection = myConnection
>>
>>             ' Someone give me the following insert statement....this
> ?
>> parameter is working,
>>             'but I modify to update statement with @ or ?, both not
>> working....
>>             'cmd.CommandText = "insert into test (picture) values
> (?)"
>>
>>             cmd.CommandText = "UPDATE bm00ts0001 SET imgarray = ?
> WHERE tid
>> = '" & vartid & "'"
>>             Dim param As SqlCeParameter =
> cmd.Parameters.Add("imgarray",
>> SqlDbType.Image)
>>             param.Value = signbyte
>>             myConnection.Open()
>>             cmd.ExecuteNonQuery()
>>             myConnection.Close()
>>
>>         Catch sqex As SqlCeException
>>             MessageBox.Show(sqex.ToString(), "DB operation failed")
>>         Catch er As Exception
>>             MessageBox.Show(er.ToString)
>>         End Try
>
>
> I've always been told that the ? syntax for parameters is an ODBC
> thing; when using a direct SQL connection you should use the @name
> parameter style. Try the following changes:
>
> Change
> cmd.CommandText = "UPDATE bm00ts0001 SET imgarray = ? WHERE tid = '" &
> vartid & "'"
> To
> cmd.CommandText = "UPDATE bm00ts0001 SET imgarray = @imgarray WHERE tid
> = '" & vartid & "'"
>
> Change
> Dim param As SqlCeParameter = cmd.Parameters.Add("imgarray",
> SqlDbType.Image)
> To
> Dim param As SqlCeParameter = cmd.Parameters.Add("@imgarray",
> SqlDbType.Image)
>
> Making these changes meant this code worked for me on a normal (not CE)
> SQL Server.
>
> --
> Larry Lard
> Replies to group please
>
Author
15 Apr 2005 8:54 AM
Larry Lard
What's your exact error message?


  A_PK wrote:
Show quoteHide quote
> Hi ....I tried the following code u gave me...i am expericing Token
Line
> Error ...what the problem could be ?
>
>
> "Larry Lard" <larryl***@hotmail.com> wrote in message
> news:1113474429.213146.101970@z14g2000cwz.googlegroups.com...
> >  A_PK wrote:
> >> Could anyone pls guide me what is wrong with my Update Command
> >>
> >>         Dim signbyte As Byte()
> >>         signbyte = GetByteArray() ' i create this function to
return
> >> ByteArray
> >>
> >>         Try
> >>             Dim cmd As New SqlCeCommand
> >>             cmd.Connection = myConnection
> >>
> >>             ' Someone give me the following insert
statement....this
> > ?
> >> parameter is working,
> >>             'but I modify to update statement with @ or ?, both
not
> >> working....
> >>             'cmd.CommandText = "insert into test (picture) values
> > (?)"
> >>
> >>             cmd.CommandText = "UPDATE bm00ts0001 SET imgarray = ?
> > WHERE tid
> >> = '" & vartid & "'"
> >>             Dim param As SqlCeParameter =
> > cmd.Parameters.Add("imgarray",
> >> SqlDbType.Image)
> >>             param.Value = signbyte
> >>             myConnection.Open()
> >>             cmd.ExecuteNonQuery()
> >>             myConnection.Close()
> >>
> >>         Catch sqex As SqlCeException
> >>             MessageBox.Show(sqex.ToString(), "DB operation
failed")
> >>         Catch er As Exception
> >>             MessageBox.Show(er.ToString)
> >>         End Try
> >
> >
> > I've always been told that the ? syntax for parameters is an ODBC
> > thing; when using a direct SQL connection you should use the @name
> > parameter style. Try the following changes:
> >
> > Change
> > cmd.CommandText = "UPDATE bm00ts0001 SET imgarray = ? WHERE tid =
'" &
> > vartid & "'"
> > To
> > cmd.CommandText = "UPDATE bm00ts0001 SET imgarray = @imgarray WHERE
tid
> > = '" & vartid & "'"
> >
> > Change
> > Dim param As SqlCeParameter = cmd.Parameters.Add("imgarray",
> > SqlDbType.Image)
> > To
> > Dim param As SqlCeParameter = cmd.Parameters.Add("@imgarray",
> > SqlDbType.Image)
> >
> > Making these changes meant this code worked for me on a normal (not
CE)
> > SQL Server.
> >
> > --
> > Larry Lard
> > Replies to group please
> >