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.VarCh ar)
myParam1.Direct ion = ParameterDirect ion.Input
myParam1.Value = txtCancType.Tex t
Dim myParam3 As New SqlParameter("@ cNum", SqlDbType.Int)
myParam3.Direct ion = ParameterDirect ion.Input
myParam3.Value = cint(session("m yID")
Dim daReg As New SqlDataAdapter
daReg.SelectCom mand = New SqlCommand
daReg.SelectCom mand.Connection = SqlConn2
daReg.SelectCom mand.CommandTex t = "updateDetails2 "
daReg.SelectCom mand.CommandTyp e = CommandType.Sto redProcedure
daReg.SelectCom mand.Parameters .Add(myParam1)
daReg.SelectCom mand.Parameters .Add(myParam3)
SqlConn2.Open()
daReg.SelectCom mand.ExecuteNon Query()
SqlConn2.Close( )
And the stored procedure is:
CREATE PROCEDURE dbo.updateDetai ls2
@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 1 1101
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.publi c.dotnet.framew ork.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.VarCh ar) myParam1.Direct ion = ParameterDirect ion.Input myParam1.Value = txtCancType.Tex t
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...E nd Try block? Dim myParam3 As New SqlParameter("@ cNum", SqlDbType.Int) myParam3.Direct ion = ParameterDirect ion.Input myParam3.Value = cint(session("m yID")
Dim daReg As New SqlDataAdapter
OK, your query does not return records, so there is no need for a data
adapter.
daReg.SelectCom mand = New SqlCommand daReg.SelectCom mand.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.SelectCom mand.CommandTex t = "updateDetails2 " daReg.SelectCom mand.CommandTyp e = CommandType.Sto redProcedure daReg.SelectCom mand.Parameters .Add(myParam1) daReg.SelectCom mand.Parameters .Add(myParam3)
SqlConn2.Open() daReg.SelectCom mand.ExecuteNon Query()
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(SqlC onn2)
Wth cmd
.CommandText = "updateDetails2 "
.CommandType = CommandType.Sto redProcedure
.Parameters.Add ("@cancType" , SqlDbType.VarCh ar, _
50).Value=txtCa ncType.Text
.Parameters.Add ("@cNum", _
SqlDbType.Int). Value=txtCancTy pe.Text
End With
Try
cmd.ExecuteNonQ uery()
Catch ex as exception
'display ex.Message
finally
SqlConn2.close( )
SqlConn2.dispos e()
end try
SqlConn2.Close( )
And the stored procedure is: CREATE PROCEDURE dbo.updateDetai ls2 @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" This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 typical MDB file runs between 1 and 4 MB.
They can be Access 97 or Access 2000 format. The
applications have been around for years. The DAO methods
are used to access the tables. During start up the Jet
interfaces are used to verify the...
|
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 running at once will there be problems
with data updates?
The reason I ask is I'm thinking like this:
User1 launches the app and the dataset is created from the data in the DB.
|
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 problem.
The sqlserver database server had windows 2000 without any SP's or updates.
This was no problem and even though the OS hadn't the .net framework
installed, everything worked fine.
the requirements for that sqlserver database server have...
|
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 which indexes
computer magazine articles for personal reference.
I am developing a Visual Basic.NET program whose sole
purpose is to enter new records into the database. No
updates to existing entries, no deletions, and no display
|
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 the project .. it errors out saying it "sql server does
not exist or access denied"
| |
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 in the good way, cause I build
that code from a book example, but nothing works.
I HAVE THIS CODE TO SAVE THE CHANGE OF THE DATASET
dstPlant.Tables("plant").Rows(intEditRow)("latin_name") = "KLHJJKJKJKHHHHHH"
|
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
"there is not an effective way of backing up mysql without either suspending
the service or causing latency problems connecting the database"
are they bull s*****g me or are they correct?
|
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 entered
manually into the second. We wish to automate this process.
The other company is proposing that the SQLServer application sets up a
trigger on a selected table in the Access backend. When a new record
is added, information can be...
|
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. Updates on the website database to be updated on the local database
(net -local)
* Updates for both databases are possibly on different fields
|
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 truncates all tables and rebuilds everything from scratch. This takes about an hour and will be run periodically.
2) A stored procedure that updates my database with the previous days activity which will be run daily. This will DELETE and INSERT but...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |