I have written a stored procedure in SQL 2005 as below.
When I call this procedure from QA with the SQL QA Test code the value of
@strNewRef is returned correctly with my limited amount of testing thus far.
When I try to use this procedure from my vb code im getting some unexpected
results.
Using the "VB Code Not Working" code I get incorrect results. The value
returned into m_strNewRef is only ever 1 char long
If I change my vb procedure to the "Working VB Code" I get correct values
returned
By messing about with "Working VB Code" I can see that by not setting the
Size property of the parameter, I get incorrect results ie only 1 character
being returned.
Could soeone please explain this behaviour
Terry Holland
SQL QA Test
=============
declare @strNewRef nvarchar(10)
exec sprGetNextItemR ef -999,@strNewRef output
select @strNewRef
VB Code Not Working
==============
Private Sub ExecuteUpdate(B yVal tr As SqlTransaction)
Using cm As SqlCommand = tr.Connection.C reateCommand()
cm.Transaction = tr
cm.CommandType = CommandType.Sto redProcedure
cm.CommandText = "sprGetNextItem Ref"
cm.Parameters.A ddWithValue("@i ntQuoteID", m_intQuoteID)
cm.Parameters.A ddWithValue("@s trItemRef", m_strNewRef)
cm.Parameters(" @strItemRef").D irection = ParameterDirect ion.Output
cm.ExecuteNonQu ery()
m_strNewRef = cm.Parameters(" @strItemRef").V alue
End Using
End Sub
If I change my vb procedure to the following I get correct values returned
Working VB Code
===============
Private Sub ExecuteUpdate(B yVal tr As SqlTransaction)
' If Not OnExecuteUpdate (tr) Then Return
Using cm As SqlCommand = tr.Connection.C reateCommand()
cm.Transaction = tr
cm.CommandType = CommandType.Sto redProcedure
cm.CommandText = "sprGetNextItem Ref"
cm.Parameters.A ddWithValue("@i ntQuoteID", m_intQuoteID)
Dim p As New SqlClient.SqlPa rameter
With p
.ParameterName = "@strItemRe f"
.SqlDbType = SqlDbType.NVarC har
.Size = 10
.Direction = ParameterDirect ion.Output
.Value = m_strNewRef
End With
cm.Parameters.A dd(p)
cm.ExecuteNonQu ery()
m_strNewRef = cm.Parameters(" @strItemRef").V alue
End Using
End Sub
Procedure
===========
USE [Contest03UK]
GO
/****** Object: StoredProcedure [dbo].[sprGetNextItemR ef] Script Date:
05/02/2007 11:22:44 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFI ER ON
GO
-- =============== =============== ===============
-- Author: <Author,,Name >
-- Create date: <Create Date,,>
-- Description: <Description, ,>
-- =============== =============== ===============
ALTER PROCEDURE [dbo].[sprGetNextItemR ef]
-- Add the parameters for the stored procedure here
@intQuoteID int,
@strItemRef nvarchar(10) = '' output
AS
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
declare @strLastRef nvarchar(10)
declare @intPointer int
declare @strLeft nvarchar(10)
declare @strRight nvarchar(10)
--Get last Item Ref for Items related to Quote
select top (1)
@strLastRef = item_txt_Refere nce
from
Item
where
item_quot_int_I D = @intQuoteID
order by
item_int_ID desc
--Set @strLastRef to 0 if the item ref
--of last item is null or empty
if @strLastRef = null
begin
set @strLastRef = 0
end
if @strLastRef = ''
begin
set @strLastRef = 0
end
/*
If last item ref is numeric the next ref should also
be numeric and it should be incremented
ie
Last Next
100 >101
10.1 >10.1
If last item ref is non-numeric the next ref should
increase the last character by 1 ascii value
ie
Last Next
1a >1b
Item 1 >Item 2
*/
if isnumeric(@strL astRef) = 1
begin
set @intPointer = charindex(N'.', @strLastRef)
if @intPointer 0
--non-integer
begin
set @strLeft = left(@strLastRe f,@intPointer-1)
set @strRight = substring(@strL astRef,@intPoin ter + 1, len(@strLastRef ))
set @strRight = convert(nvarcha r(10), convert(int, @strRight)+1)
set @strItemRef = @strLeft + '.' + @strRight
end
else
begin
--integer
set @strItemRef = convert(nvarcha r(10), convert(int, @strLastRef)+1)
end
end
else
begin
--not numeric
set @strLeft = left(@strLastRe f,len(@strLastR ef)-1)
set @strRight = right(@strLastR ef,1)
set @strRight = char(ascii(@str Right)+1)
set @strItemRef = @strLeft + @strRight
end 0 1175 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Stefan Berglund |
last post by:
I was looking for a general consensus as to whether the ActiveConnection property of the command
object should be set to Nothing or whether it's sufficient to set the command object itself to
nothing.
I also seem to be forced to use the Parameters.Append method, since I was unable to make the
statement Set rs = .Execute(,Array(strShowID,strSort),adCmdStoredProc) work without error.
I'm guessing that while they're both Variants, one is a...
|
by: Bruno Alexandre |
last post by:
Hi guys,
withou using SP, I want to be able to add a Parameter to the SQL Query and
retrive the Recordset so I can use the Paging property under the recorset
object.... how can I do this?
I'm stuck here.
|
by: Teo |
last post by:
Hi! Sorry for my many postings on this Newsgroup. I am new to ADO.NET and I
got Sceppa's book on ADO.NET. It's a great book but covers a lot on the
DataAdapter and Offline Data. Now, if I want to Insert Data into my MSDE
Database, can I do it without using the DataAdapter?
Here are the steps I use to insert the data.
Open Connection
Add Parameters, set direction and specify value.
Call my connection.ExecuteNonQuery()
Close the Connection.
|
by: Elliot M. Rodriguez |
last post by:
I implemented a very small, basic data access layer for my web application.
It works just fine, except for this one bug.
One of my methods returns an abstracted dataset. To accomodate X number of
input parameters, I created a function signature that accepts a ParamArray
of SqlParameters as well as the name of the stored proc. In the body of the
function I loop through the param array and append each object to the
Parameters collection of...
|
by: Gene |
last post by:
What can I do if I want to get the result using the sql command?
for example,
the select command is "select Name from Employee where StaffID=10"
How to get the "Name"???
dim Name as string
and then.....
what should I do?
| |
by: Ed |
last post by:
Hi,
I want to load data to a table in Sql Server from a
dataset table in my vb.net app using a dataAdapter. I
know how to do this as follows (my question is to see if I
can reduce the amount of code below):
....
Dim DA As SqlDataAdapter = New SqlDataAdapter
Dim Parm As New SqlParameter
....
|
by: mabond |
last post by:
Hi
VB.NET 2005 Express edition
Microsoft Access 2000 (SP-3)
Having trouble writing an "insert into" command for a Microsoft table I'm
accessing through oledb.
I've tried to follow the same principle I'd use if it was an sql database
but I'm getting an error telling me the syntax of the "insert into" command
|
by: explode |
last post by:
I made nova oledbdataadapter select update insert and delete command and
connection veza. dataset is Studenti1data, I made it by the new data source
wizard,and made datagridview and bindingsource draging Table1 to Form2. The
select command works fine, but when I change the data and call update
command I get a syntax error:
System.Data.OleDb.OleDbException was unhandled
ErrorCode=-2147217900
Message="Syntax error in UPDATE statement."...
|
by: iKiLL |
last post by:
Hi all
I am having problems getting my SqlCeDataAdapter to Update the SQL Mobile
Data base.
i am using C# CF2.
I have tried this a number of different ways. Starting with the command
builder but eventually i wrote out the entire command my self, and still
nothing.
The only thing that i can think this that because i am trying to add a table
that is created outside the data adaptor and then Merge/Copy the data into
|
by: Sagar |
last post by:
Hi.
I am working on a project to migrate a web application from 1.1 to 2.0
Within in the DAL of the application, there is a call to below
function that builds a command object for later use.
Inside this function iam getting a runtime error when the command
object calls the prepare method.
|
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: 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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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 we have to send another system
| |
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...
| |