473,503 Members | 12,103 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Database Updates Failing

I have a small problem which I am sure is easily resolved but my lack of ASP
experience is holdng me back so I'm hoping someone can assist.
I have a very simple procedure which involves a user updating a field value
on an ASP.Net page, clicking a button which then kicks off an SQL stored
procedure to update the underlying table. The problem is the update is being
ignored, there are no error messages. If I run the procedure from query
analyser it works.
My code is:
Dim myParam1 As New SqlParameter("@cancType", SqlDbType.VarChar)
myParam1.Direction = ParameterDirection.Input
myParam1.Value = txtCancType.Text

Dim myParam3 As New SqlParameter("@cNum", SqlDbType.Int)
myParam3.Direction = ParameterDirection.Input
myParam3.Value = cint(session("myID")

Dim daReg As New SqlDataAdapter
daReg.SelectCommand = New SqlCommand
daReg.SelectCommand.Connection = SqlConn2
daReg.SelectCommand.CommandText = "updateDetails2"
daReg.SelectCommand.CommandType = CommandType.StoredProcedure
daReg.SelectCommand.Parameters.Add(myParam1)
daReg.SelectCommand.Parameters.Add(myParam3)

SqlConn2.Open()
daReg.SelectCommand.ExecuteNonQuery()
SqlConn2.Close()

And the stored procedure is:
CREATE PROCEDURE dbo.updateDetails2
@cancType varchar(50),
@cNum int

As
update PatientDetails
set cancType = @cancType--,basics_FK = @basicsFK
where basics_FK = @cNum
GO

In the PatientDetails table the basics_FK field is set up as "int".

Any/all constructive suggestions appreciated.

Thanks

WW
Nov 5 '05 #1
1 1094
Will wrote:
I have a small problem which I am sure is easily resolved but my lack
of ASP experience is holdng me back so I'm hoping someone can assist.
I have a very simple procedure which involves a user updating a field
value on an ASP.Net page,
There was no way for you to know it, but this is a classic asp newsgroup
(which is much different from ASP.Net).
While you may be lucky enough to find a dotnet-knowledgeable person here who
can answer your question, you can eliminate the luck factor by posting your
question to a group where those dotnet-knowledgeable people hang out. I
suggest microsoft.public.dotnet.framework.aspnet.

However, read on:
clicking a button which then kicks off an
SQL stored procedure to update the underlying table. The problem is
the update is being ignored, there are no error messages.
A good tool to use is SQL Profiler (in the SQL Server program group in your
Windows Start menu). A trace will show what is happening.

Are you using Visual Studio? if so, have you attempted to debug this code?
If not, you can turn tracing on in web.config. Check out the documentation
at msdn.microsoft.com/library
If I run
the procedure from query analyser it works.
My code is:
Dim myParam1 As New SqlParameter("@cancType", SqlDbType.VarChar)
myParam1.Direction = ParameterDirection.Input
myParam1.Value = txtCancType.Text
You never set the length parameter. Non-fixed-length datatypes require the
length to be set. I'm surprised executing the command did not raise an
error. Are you sure this entire section isn't enclosed in a
Try...Catch...End Try block?

Dim myParam3 As New SqlParameter("@cNum", SqlDbType.Int)
myParam3.Direction = ParameterDirection.Input
myParam3.Value = cint(session("myID")

Dim daReg As New SqlDataAdapter
OK, your query does not return records, so there is no need for a data
adapter.
daReg.SelectCommand = New SqlCommand
daReg.SelectCommand.Connection = SqlConn2
Why "SqlConn2"? This implies that this is the second connection object on
this page. Are you dealing with two separate sql servers?
daReg.SelectCommand.CommandText = "updateDetails2"
daReg.SelectCommand.CommandType = CommandType.StoredProcedure
daReg.SelectCommand.Parameters.Add(myParam1)
daReg.SelectCommand.Parameters.Add(myParam3)

SqlConn2.Open()
daReg.SelectCommand.ExecuteNonQuery()
A simpler version follows (I usually open my connection first, that way I
avoid running all those other lines of code if the connection fails):

SqlConn2.Open()
Dim cmd as New SqlCommand(SqlConn2)
Wth cmd
.CommandText = "updateDetails2"
.CommandType = CommandType.StoredProcedure
.Parameters.Add("@cancType", SqlDbType.VarChar, _
50).Value=txtCancType.Text
.Parameters.Add("@cNum", _
SqlDbType.Int).Value=txtCancType.Text
End With
Try
cmd.ExecuteNonQuery()
Catch ex as exception
'display ex.Message
finally
SqlConn2.close()
SqlConn2.dispose()
end try
SqlConn2.Close()

And the stored procedure is:
CREATE PROCEDURE dbo.updateDetails2
@cancType varchar(50),
@cNum int

As
/%
It is good practice to use the following command in all procedures to
be run via ADO/ADO.Net - google it to see why
%/

SET NOCOUNT ON
update PatientDetails
set cancType = @cancType--,basics_FK = @basicsFK
where basics_FK = @cNum
GO


If you still have problems, and neither tracing nor SQL Profiler help,
gollow up in the aspnet group.

Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Nov 5 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1624
by: David | last post by:
Hello, I have several applications that maintain a Jet database via ODBC. There are perhaps two dozen tables, ony two of which have perhaps 10,000 records each. The rest are rather small. A...
3
12996
by: Tc | last post by:
Hi, I was curious, I am thinking of writing an application that loads a dataset from a database that resides on a server. The question I have is this, if multiple copies of the app will be...
5
1935
by: Daniel Bass | last post by:
I setup a asp.net project running on http://localhost/ which connects to a database on another server running sqlserver... I was able to connect to the database and create my application no...
0
5797
by: M. David Johnson | last post by:
I cannot get my OleDbDataAdapter to update my database table from my local dataset table. The Knowledge Base doesn't seem to help - see item 10 below. I have a Microsoft Access 2000 database...
18
1951
by: Jon Delano | last post by:
Hey all I am building a new computer. I have Windows XP Pro with SP2 and all the updates. I installed VS 2003. Then copied a project from my old computer to the new one. When I try and run...
7
3351
by: Jean Christophe Avard | last post by:
Hi! I have a dataset that retreive all the item information from the database. I need to be able to edit them, in the dataset and in the database. I have this code, could anyone tell me if I'm...
5
4079
by: mantrid | last post by:
Hello My web hosting company has lost my data due to the mysql software failing, it only affected those people using innoDB engine. I asked them why they didnt restore from a back up. They said...
4
6979
by: Jim Devenish | last post by:
We have an Access database with Access front-end to Access back-end. Another company has installed a separate application using SQLServer. At present certain information in the first application is...
0
2904
by: D0c | last post by:
Hey, I would like to syncronize my local database with my website database. Scenarios are 1. New rows / row updates in the local database to be updated on the website database (local -net) 2....
1
1688
by: trd79 | last post by:
Hi, I am extracting data from an operational system in order to maintain a mirror that can be used for reporting. I have two means of filling this database: 1) A stored procedure which...
0
7212
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7296
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7364
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5604
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4696
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1524
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.