Showing posts with label return. Show all posts
Showing posts with label return. Show all posts

Thursday, March 8, 2012

cannot update database but there were no error!

hai..i cannot solve this sproblem...i need to update my databse after i edited the textfield.then system will return me 'UPDATE SUCCESS'(because i return value UPDATE SUCCESS).this seem like nothing wrong.but when i check the database,data did not update!!have anybody know that?

thanks!!my coding as below,

#Region "Edit student Then save"


Public Function editstudent(ByVal sIC As String, ByVal school As String, ByVal phone As String, ByVal pic As String, ByVal pwd As String, ByVal sname As String, ByVal gender As String, ByVal add As String, ByVal standard As String, ByVal osic As String) As String

' Create Instance of Connection and Command Object
Dim myConnection As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))

Dim command As String
Dim mycommand As SqlCommand

command = "Update student_info set sic=@.sic, Spassword=@.pwd," & _
"sname=@.sname,sphone=@.phone,saddress=@.add,sstandard=@.standard,sschool=@.school ,Sparent_IC=@.pic ,sGender=@.gender Where sic=@.osic"

mycommand = New SqlCommand(command, myConnection)
mycommand.CommandType = CommandType.Text

'' Add Parameters to Command
Dim parameterIC As SqlParameter = New SqlParameter("@.sic", SqlDbType.VarChar, 12)
parameterIC .Value = sIC
mycommand.Parameters.Add(parameterIC )


Dim parameteroIC As SqlParameter = New SqlParameter("@.osic", SqlDbType.VarChar, 12)
parameteroIC .Value = osic
mycommand.Parameters.Add(parameteroIC )

Dim parameterpwd As SqlParameter = New SqlParameter("@.pwd", SqlDbType.VarChar, 50)
parameterpwd .Value = pwd
mycommand.Parameters.Add(parameterpwd )

Dim parametername As SqlParameter = New SqlParameter("@.sname", SqlDbType.VarChar, 100)
parametername .Value = sname
mycommand.Parameters.Add(parametername )

Dim parameteradd As SqlParameter = New SqlParameter("@.add", SqlDbType.VarChar, 100)
parameteradd .Value = add
mycommand.Parameters.Add(parameteradd )

Dim parameterphone As SqlParameter = New SqlParameter("@.phone", SqlDbType.VarChar, 12)
parameterphone.Value = phone
mycommand.Parameters.Add(parameterphone)

Dim parameterstandard As SqlParameter = New SqlParameter("@.standard", SqlDbType.VarChar, 50)
parameterstandard.Value = standard
mycommand.Parameters.Add(parameterstandard)

Dim parametersschool As SqlParameter = New SqlParameter("@.school", SqlDbType.VarChar, 100)
parametersschool.Value = school
mycommand.Parameters.Add(parametersschool)

Dim parameterpic As SqlParameter = New SqlParameter("@.pic", SqlDbType.VarChar, 12)
parameterpic.Value = pic
mycommand.Parameters.Add(parameterpic)

Dim parametergender As SqlParameter = New SqlParameter("@.gender", SqlDbType.VarChar, 1)
parametergender.Value = gender
mycommand.Parameters.Add(parametergender)
Try

myConnection.Open()
mycommand.ExecuteNonQuery()
myConnection.Close()
Return "Update Success !!!"

Catch exc As Exception

Return exc.ToString

End Try

End Function
#End Region


End Class

Hi,

It is a working code on my tests.

Open the sql profiler and trace your statement. If you do not see your sql command in the profiler then check the connection string.

If it is listed in the profiler screen then use that sql statement to improve your results.

(hint for profiler, change the name of the column "password" to "pwd" otherwise sql will not be listed in the profiler)

Eralper

|||

Sound like the following is the cause of your confusion:

Depending on how you have your debugging environment set up, when you start your application, it makes a copy of all your source files somewhere else, then runs it. When that happens it also happens to make a copy of your database, so your applications makes changes to the new copy of the database, but whatever tool you are using to check the database is looking at the original. Of course restarting the application causes it to copy over the new copy with the original again.

Sunday, February 12, 2012

Cannot return results of temporary table

Hi,
I've written a stored procedure which loops over several tables, processes
the data and stores the processed results in a temporary table.
At the end of the procedure, I'd like to return a 'select *' from the
temporary table to an ASP page, from where I call the stored procedure.
The procedure works, I can execute it and view the results in my Query
Analyzer, but I get an error when I call the procedure from my ASP page.
The error I receive is 'Operation is not allowed when the object is
closed'. I've read on the net that a temporary table is closed and removed
as soon as the stored procedure ends - could this be the problem?
The line on which the error occurs is:
if not (rec.eof) and not (rec.bof) then
(the place where i first use the recordset given to me by the stored
procedure.
Anyway, I'm at a loss here as to how I can solve this problem. Any help is
greatly appreciated.
Thanks,
JayCee
--
http://jcsnippets.atspace.com
a collection of source code, tips and tricksJust add "set nocount on" as the very first line after "as" in your sproc.
-oj
"jcsnippets.atspace.com" <admin@.jcsnippets.atspace.com> wrote in message
news:Xns97805DB2D943Cadminjcsnippetsatsp
a@.195.238.0.34...
> Hi,
> I've written a stored procedure which loops over several tables, processes
> the data and stores the processed results in a temporary table.
> At the end of the procedure, I'd like to return a 'select *' from the
> temporary table to an ASP page, from where I call the stored procedure.
> The procedure works, I can execute it and view the results in my Query
> Analyzer, but I get an error when I call the procedure from my ASP page.
> The error I receive is 'Operation is not allowed when the object is
> closed'. I've read on the net that a temporary table is closed and removed
> as soon as the stored procedure ends - could this be the problem?
> The line on which the error occurs is:
> if not (rec.eof) and not (rec.bof) then
> (the place where i first use the recordset given to me by the stored
> procedure.
> Anyway, I'm at a loss here as to how I can solve this problem. Any help is
> greatly appreciated.
> Thanks,
> JayCee
> --
> http://jcsnippets.atspace.com
> a collection of source code, tips and tricks|||hi,
Could you please so kind to show us that code snippet?
--
current location: alicante (es)
"jcsnippets.atspace.com" wrote:

> Hi,
> I've written a stored procedure which loops over several tables, processes
> the data and stores the processed results in a temporary table.
> At the end of the procedure, I'd like to return a 'select *' from the
> temporary table to an ASP page, from where I call the stored procedure.
> The procedure works, I can execute it and view the results in my Query
> Analyzer, but I get an error when I call the procedure from my ASP page.
> The error I receive is 'Operation is not allowed when the object is
> closed'. I've read on the net that a temporary table is closed and removed
> as soon as the stored procedure ends - could this be the problem?
> The line on which the error occurs is:
> if not (rec.eof) and not (rec.bof) then
> (the place where i first use the recordset given to me by the stored
> procedure.
> Anyway, I'm at a loss here as to how I can solve this problem. Any help is
> greatly appreciated.
> Thanks,
> JayCee
> --
> http://jcsnippets.atspace.com
> a collection of source code, tips and tricks
>|||"oj" <nospam_ojngo@.home.com> wrote in
news:OfUOBnoQGHA.1160@.TK2MSFTNGP09.phx.gbl:

> Just add "set nocount on" as the very first line after "as" in your
> sproc.
>
Alas, that did not solve my problem...
Best regards,
JayCee
--
http://jcsnippets.atspace.com
a collection of source code, tips and tricks|||examnotes <Enric@.discussions.microsoft.com> wrote in
news:2E51C9AF-3A4A-4277-926E-578691A83FCF@.microsoft.com:

> hi,
> Could you please so kind to show us that code snippet?
Of course - I should have posted this right away. Here is the code - if I
leave out the code marked '-- problem --', and only do the test insert,
the code works fine.
-- Code
alter procedure log_getProductHits
(
@.custid int,
@.category int
)
as
set nocount on
begin
declare @.seq1 int
declare @.seq2 int
declare @.name1 varchar(100)
declare @.name2 varchar(100)
declare @.count1 int
declare @.count2 int
create table #temphits
(
product varchar(100),
hits int
)
insert into #temphits values ('product', 15)
-- PROBLEM --
-- Get category level 1
if (@.category is null)
begin
declare cat1 cursor for
select seq
from cat_pd_cat
where custid = @.custid
and parent_seq is null
end
else
begin
declare cat1 cursor for
select seq
from cat_pd_cat
where custid = @.custid
and parent_seq = @.category
end
open cat1
fetch cat1 into @.seq1
while (@.@.FETCH_STATUS = 0)
begin
print 'Seq1: ' + cast(@.seq1 as varchar)
-- Insert valid products
declare prod1 cursor for
select cat_pd_product.name, count(*)
from cat_dom_productlog,
cat_pd_product
where cat_dom_productlog.custid = @.custid
and cat_dom_productlog.cat_pd_cat = @.seq1
and cat_pd_product.seq =
cat_dom_productlog.cat_pd_product
group by cat_pd_product.name
order by cat_pd_product.name
open prod1
fetch prod1 into @.name1, @.count1
while (@.@.FETCH_STATUS = 0)
begin
insert into #temphits values (@.name1, @.count1)
fetch prod1 into @.name1, @.count1
end
close prod1
deallocate prod1
fetch cat1 into @.seq1
end
close cat1
deallocate cat1
-- PROBLEM --
select * from #temphits order by product
end
-- /Code
Best regards,
JayCee
--
http://jcsnippets.atspace.com
a collection of source code, tips and tricks|||That error means that the recordset within ASP is closed. If your procedure
works in query analyzer but gives this error in ASP then the error is in
your ASP code. Verify the SQL command and all the parameters immediately
before calling your stored procedure. Output them all to the page then
execute the stored procedure in query analyzer with the displayed
parameters.
Use cut and paste to do this. The problem could be as simple as a typo, or
a parameter could be blank, etc. Your connection string could also be
invalid.
Posting your ASP code might provide some insight as well.
"jcsnippets.atspace.com" <admin@.jcsnippets.atspace.com> wrote in message
news:Xns97805DB2D943Cadminjcsnippetsatsp
a@.195.238.0.34...
> Hi,
> I've written a stored procedure which loops over several tables, processes
> the data and stores the processed results in a temporary table.
> At the end of the procedure, I'd like to return a 'select *' from the
> temporary table to an ASP page, from where I call the stored procedure.
> The procedure works, I can execute it and view the results in my Query
> Analyzer, but I get an error when I call the procedure from my ASP page.
> The error I receive is 'Operation is not allowed when the object is
> closed'. I've read on the net that a temporary table is closed and removed
> as soon as the stored procedure ends - could this be the problem?
> The line on which the error occurs is:
> if not (rec.eof) and not (rec.bof) then
> (the place where i first use the recordset given to me by the stored
> procedure.
> Anyway, I'm at a loss here as to how I can solve this problem. Any help is
> greatly appreciated.
> Thanks,
> JayCee
> --
> http://jcsnippets.atspace.com
> a collection of source code, tips and tricks|||"Jim Underwood" <james.underwoodATfallonclinic.com> wrote in
news:OXvPtyrQGHA.5808@.TK2MSFTNGP12.phx.gbl:

> That error means that the recordset within ASP is closed. If your
> procedure works in query analyzer but gives this error in ASP then the
> error is in your ASP code. Verify the SQL command and all the
> parameters immediately before calling your stored procedure. Output
> them all to the page then execute the stored procedure in query
> analyzer with the displayed parameters.
> Use cut and paste to do this. The problem could be as simple as a
> typo, or a parameter could be blank, etc. Your connection string
> could also be invalid.
> Posting your ASP code might provide some insight as well.
It appears that the error was not in the ASP page, it was in the stored
procedure.
After tampering with the procedure, I found out that I should have written
select * from #temphits order by product
instead of
return select * from #temphits order by product
at the end of the stored procedure.
Thanks to everyone who took the trouble to reply!
Best regards,
JayCee
--
http://jcsnippets.atspace.com
a collection of source code, tips and tricks