473,241 Members | 1,608 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,241 software developers and data experts.

Returning a value from a stored proc

Here is the proc:

CREATE PROCEDURE [dbo].[sp_CheckNetName]
@CID as int,
@Netname as nvarchar(25),
@Return as int OUTPUT
AS
IF EXISTS (SELECT DISTINCT netname FROM computers WHERE CompanyID = @CID AND UPPER(netname) = UPPER(@Netname))
SELECT @Return = 1
ELSE
SELECT @Return = 0
GO

Which this works great in query analyzer.... Now here is the ASP.NET script to load this proc:

Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyDataAdapter As SqlDataAdapter

MyConnection = New SqlConnection(sqlconn)
MyDataAdapter = New SqlDataAdapter("sp_CheckNetName", MyConnection)
MyDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure

MyDataAdapter.SelectCommand.Parameters.Add(New SqlParameter("@CID", SqlDbType.int, 4))
MyDataAdapter.SelectCommand.Parameters("@CID").Val ue = Trim(request("COMPID"))

MyDataAdapter.SelectCommand.Parameters.Add(New SqlParameter("@Netname", SqlDbType.VarChar, 25))
MyDataAdapter.SelectCommand.Parameters("@Netname") .Value = Trim(netname.text)

MyDataAdapter.SelectCommand.Parameters.Add(New SqlParameter("@Return", SqlDbType.Int, 4))
MyDataAdapter.SelectCommand.Parameters("@Return"). Direction = ParameterDirection.Output

DS = New DataSet()
MyDataAdapter.Fill(DS, "Net")

results.Text = MyDataAdapter.SelectCommand.Parameters(2).Value

MyDataAdapter.Dispose()
MyConnection.Close()

The results always displays 0, however in queryanalyzer, it will display the appropriate response.

Thanks!

--
David Lozzi
Web Applications/Network Specialist
Delphi Technology Solutions, Inc.
dlozzi(remove-this)@delphi-ts.com
Nov 18 '05 #1
6 2238
David,

This might help...
CREATE PROCEDURE [dbo].[sp_CheckNetName]
(
@CID int,
@Netname nvarchar(25)
)
AS
IF EXISTS (SELECT DISTINCT netname FROM computers WHERE CompanyID = @CID AND UPPER(netname) = UPPER(@Netname))
RETURN 1
ELSE
RETURN 0
GO

--------------

Dim MyConnection As SqlConnection
Dim MyConnection As SqlCommand

MyConnection = New SqlConnection(sqlconn)
MyCommand = new SqlCommand("sp_CheckNetName", MyConnection)
MyCommand.CommandType = CommandType.StoredProcedure

MyCommand.Parameters.Add("@CID", SqlDbType.int, 4)
MyCommand.Parameters("@CID").Value = Trim(request("COMPID"))

MyCommand.Parameters.Add("@Netname", SqlDbType.VarChar, 25)
MyCommand.Parameters("@Netname").Value = Trim(netname.text)

MyCommand.Parameters.Add("@Return", SqlDbType.Int, 4)
MyCommand.Parameters("@Return").Direction = ParameterDirection.ReturnValue;


sqlconn.Open();
MyCommand.ExecuteNonQuery();
sqlconn.Dispose();
results.Text = MyDataAdapter.SelectCommand.Parameters(2).Value;


There is no need to use a DataAdapter here. Just execute the command directly. Also, although I have not changed it in the code above, refrain from using "sp_" as a prefix for stored procedures as SQL Server will look for the procedure in the Master DB before looking in your database, causing a slight degredation in performance.
--
Edd Connolly

MCP 70-315

"David Lozzi" <dlozzi(remove-this)@delphi-ts.com> wrote in message news:eE**************@TK2MSFTNGP10.phx.gbl...
Here is the proc:

CREATE PROCEDURE [dbo].[sp_CheckNetName]
@CID as int,
@Netname as nvarchar(25),
@Return as int OUTPUT
AS
IF EXISTS (SELECT DISTINCT netname FROM computers WHERE CompanyID = @CID AND UPPER(netname) = UPPER(@Netname))
SELECT @Return = 1
ELSE
SELECT @Return = 0
GO

Which this works great in query analyzer.... Now here is the ASP.NET script to load this proc:

Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyDataAdapter As SqlDataAdapter

MyConnection = New SqlConnection(sqlconn)
MyDataAdapter = New SqlDataAdapter("sp_CheckNetName", MyConnection)
MyDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure

MyDataAdapter.SelectCommand.Parameters.Add(New SqlParameter("@CID", SqlDbType.int, 4))
MyDataAdapter.SelectCommand.Parameters("@CID").Val ue = Trim(request("COMPID"))

MyDataAdapter.SelectCommand.Parameters.Add(New SqlParameter("@Netname", SqlDbType.VarChar, 25))
MyDataAdapter.SelectCommand.Parameters("@Netname") .Value = Trim(netname.text)

MyDataAdapter.SelectCommand.Parameters.Add(New SqlParameter("@Return", SqlDbType.Int, 4))
MyDataAdapter.SelectCommand.Parameters("@Return"). Direction = ParameterDirection.Output

DS = New DataSet()
MyDataAdapter.Fill(DS, "Net")

results.Text = MyDataAdapter.SelectCommand.Parameters(2).Value

MyDataAdapter.Dispose()
MyConnection.Close()

The results always displays 0, however in queryanalyzer, it will display the appropriate response.

Thanks!

--
David Lozzi
Web Applications/Network Specialist
Delphi Technology Solutions, Inc.
dlozzi(remove-this)@delphi-ts.com
Nov 18 '05 #2
David,

The last line should have read:

results.Text = MyCommand.Parameters(2).Value;
--
Edd Connolly

MCP 70-315

"Edd Connolly" <ed******************@hotmail.com> wrote in message news:Je*****************@newsfe3-gui.ntli.net...
David,

This might help...
CREATE PROCEDURE [dbo].[sp_CheckNetName]
(
@CID int,
@Netname nvarchar(25)
)
AS
IF EXISTS (SELECT DISTINCT netname FROM computers WHERE CompanyID = @CID AND UPPER(netname) = UPPER(@Netname))
RETURN 1
ELSE
RETURN 0
GO

--------------

Dim MyConnection As SqlConnection
Dim MyConnection As SqlCommand

MyConnection = New SqlConnection(sqlconn)
MyCommand = new SqlCommand("sp_CheckNetName", MyConnection)
MyCommand.CommandType = CommandType.StoredProcedure

MyCommand.Parameters.Add("@CID", SqlDbType.int, 4)
MyCommand.Parameters("@CID").Value = Trim(request("COMPID"))

MyCommand.Parameters.Add("@Netname", SqlDbType.VarChar, 25)
MyCommand.Parameters("@Netname").Value = Trim(netname.text)

MyCommand.Parameters.Add("@Return", SqlDbType.Int, 4)
MyCommand.Parameters("@Return").Direction = ParameterDirection.ReturnValue;


sqlconn.Open();
MyCommand.ExecuteNonQuery();
sqlconn.Dispose();
results.Text = MyDataAdapter.SelectCommand.Parameters(2).Value;


There is no need to use a DataAdapter here. Just execute the command directly. Also, although I have not changed it in the code above, refrain from using "sp_" as a prefix for stored procedures as SQL Server will look for the procedure in the Master DB before looking in your database, causing a slight degredation in performance.
--
Edd Connolly

MCP 70-315

"David Lozzi" <dlozzi(remove-this)@delphi-ts.com> wrote in message news:eE**************@TK2MSFTNGP10.phx.gbl...
Here is the proc:

CREATE PROCEDURE [dbo].[sp_CheckNetName]
@CID as int,
@Netname as nvarchar(25),
@Return as int OUTPUT
AS
IF EXISTS (SELECT DISTINCT netname FROM computers WHERE CompanyID = @CID AND UPPER(netname) = UPPER(@Netname))
SELECT @Return = 1
ELSE
SELECT @Return = 0
GO

Which this works great in query analyzer.... Now here is the ASP.NET script to load this proc:

Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyDataAdapter As SqlDataAdapter

MyConnection = New SqlConnection(sqlconn)
MyDataAdapter = New SqlDataAdapter("sp_CheckNetName", MyConnection)
MyDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure

MyDataAdapter.SelectCommand.Parameters.Add(New SqlParameter("@CID", SqlDbType.int, 4))
MyDataAdapter.SelectCommand.Parameters("@CID").Val ue = Trim(request("COMPID"))

MyDataAdapter.SelectCommand.Parameters.Add(New SqlParameter("@Netname", SqlDbType.VarChar, 25))
MyDataAdapter.SelectCommand.Parameters("@Netname") .Value = Trim(netname.text)

MyDataAdapter.SelectCommand.Parameters.Add(New SqlParameter("@Return", SqlDbType.Int, 4))
MyDataAdapter.SelectCommand.Parameters("@Return"). Direction = ParameterDirection.Output

DS = New DataSet()
MyDataAdapter.Fill(DS, "Net")

results.Text = MyDataAdapter.SelectCommand.Parameters(2).Value

MyDataAdapter.Dispose()
MyConnection.Close()

The results always displays 0, however in queryanalyzer, it will display the appropriate response.

Thanks!

--
David Lozzi
Web Applications/Network Specialist
Delphi Technology Solutions, Inc.
dlozzi(remove-this)@delphi-ts.com
Nov 18 '05 #3
Edd,

what language is this in?

--
David Lozzi
Web Applications/Network Specialist
Delphi Technology Solutions, Inc.
dlozzi(remove-this)@delphi-ts.com
"Edd Connolly" <ed******************@hotmail.com> wrote in message news:si****************@newsfe3-gui.ntli.net...
David,

The last line should have read:

results.Text = MyCommand.Parameters(2).Value;
--
Edd Connolly

MCP 70-315

"Edd Connolly" <ed******************@hotmail.com> wrote in message news:Je*****************@newsfe3-gui.ntli.net...
David,

This might help...
CREATE PROCEDURE [dbo].[sp_CheckNetName]
(
@CID int,
@Netname nvarchar(25)
)
AS
IF EXISTS (SELECT DISTINCT netname FROM computers WHERE CompanyID = @CID AND UPPER(netname) = UPPER(@Netname))
RETURN 1
ELSE
RETURN 0
GO

--------------

Dim MyConnection As SqlConnection
Dim MyConnection As SqlCommand

MyConnection = New SqlConnection(sqlconn)
MyCommand = new SqlCommand("sp_CheckNetName", MyConnection)
MyCommand.CommandType = CommandType.StoredProcedure

MyCommand.Parameters.Add("@CID", SqlDbType.int, 4)
MyCommand.Parameters("@CID").Value = Trim(request("COMPID"))

MyCommand.Parameters.Add("@Netname", SqlDbType.VarChar, 25)
MyCommand.Parameters("@Netname").Value = Trim(netname.text)

MyCommand.Parameters.Add("@Return", SqlDbType.Int, 4)
MyCommand.Parameters("@Return").Direction = ParameterDirection.ReturnValue;


sqlconn.Open();
MyCommand.ExecuteNonQuery();
sqlconn.Dispose();
results.Text = MyDataAdapter.SelectCommand.Parameters(2).Value;


There is no need to use a DataAdapter here. Just execute the command directly. Also, although I have not changed it in the code above, refrain from using "sp_" as a prefix for stored procedures as SQL Server will look for the procedure in the Master DB before looking in your database, causing a slight degredation in performance.
--
Edd Connolly

MCP 70-315

"David Lozzi" <dlozzi(remove-this)@delphi-ts.com> wrote in message news:eE**************@TK2MSFTNGP10.phx.gbl...
Here is the proc:

CREATE PROCEDURE [dbo].[sp_CheckNetName]
@CID as int,
@Netname as nvarchar(25),
@Return as int OUTPUT
AS
IF EXISTS (SELECT DISTINCT netname FROM computers WHERE CompanyID = @CID AND UPPER(netname) = UPPER(@Netname))
SELECT @Return = 1
ELSE
SELECT @Return = 0
GO

Which this works great in query analyzer.... Now here is the ASP.NET script to load this proc:

Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyDataAdapter As SqlDataAdapter

MyConnection = New SqlConnection(sqlconn)
MyDataAdapter = New SqlDataAdapter("sp_CheckNetName", MyConnection)
MyDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure

MyDataAdapter.SelectCommand.Parameters.Add(New SqlParameter("@CID", SqlDbType.int, 4))
MyDataAdapter.SelectCommand.Parameters("@CID").Val ue = Trim(request("COMPID"))

MyDataAdapter.SelectCommand.Parameters.Add(New SqlParameter("@Netname", SqlDbType.VarChar, 25))
MyDataAdapter.SelectCommand.Parameters("@Netname") .Value = Trim(netname.text)

MyDataAdapter.SelectCommand.Parameters.Add(New SqlParameter("@Return", SqlDbType.Int, 4))
MyDataAdapter.SelectCommand.Parameters("@Return"). Direction = ParameterDirection.Output

DS = New DataSet()
MyDataAdapter.Fill(DS, "Net")

results.Text = MyDataAdapter.SelectCommand.Parameters(2).Value

MyDataAdapter.Dispose()
MyConnection.Close()

The results always displays 0, however in queryanalyzer, it will display the appropriate response.

Thanks!

--
David Lozzi
Web Applications/Network Specialist
Delphi Technology Solutions, Inc.
dlozzi(remove-this)@delphi-ts.com
Nov 18 '05 #4
No such luck. First off, I believe you were writing in jscript? I had to remove the ;. I am getting the same results, it is only returning 0. Here's the new proc:

CREATE PROCEDURE [dbo].[sp_CheckNetName]
@CID as int,
@Netname as nvarchar(25)
AS

IF EXISTS (SELECT DISTINCT netname FROM computers WHERE CompanyID = @CID AND UPPER(netname) = UPPER(@Netname))
Return 1
ELSE
Return 0
GO

And here is what my VB looks like now:

sub checkNetName(sender as object, e as eventargs)
Dim MyConnection As SqlConnection
Dim MyCommand As SqlCommand

MyConnection = New SqlConnection(sqlconn)
MyCommand = new SqlCommand("sp_CheckNetName", MyConnection)
MyCommand.CommandType = CommandType.StoredProcedure

MyCommand.Parameters.Add("@CID", SqlDbType.int, 4)
MyCommand.Parameters("@CID").Value = Trim(request("COMPID"))

MyCommand.Parameters.Add("@Netname", SqlDbType.VarChar, 25)
MyCommand.Parameters("@Netname").Value = Trim(netname.text)

MyCommand.Parameters.Add("@Return", SqlDbType.Int, 4)
MyCommand.Parameters("@Return").Direction = ParameterDirection.ReturnValue

myconnection.Open()
MyCommand.ExecuteNonQuery()
myconnection.Dispose()
results.Text = MyCommand.Parameters(2).Value
end sub
Could it be the EXISTS? Is there another way of checking to see if a value is contained in a table?

THANKS!
--
David Lozzi
Web Applications/Network Specialist
Delphi Technology Solutions, Inc.
dlozzi(remove-this)@delphi-ts.com
"Edd Connolly" <ed******************@hotmail.com> wrote in message news:si****************@newsfe3-gui.ntli.net...
David,

The last line should have read:

results.Text = MyCommand.Parameters(2).Value;
--
Edd Connolly

MCP 70-315

"Edd Connolly" <ed******************@hotmail.com> wrote in message news:Je*****************@newsfe3-gui.ntli.net...
David,

This might help...
CREATE PROCEDURE [dbo].[sp_CheckNetName]
(
@CID int,
@Netname nvarchar(25)
)
AS
IF EXISTS (SELECT DISTINCT netname FROM computers WHERE CompanyID = @CID AND UPPER(netname) = UPPER(@Netname))
RETURN 1
ELSE
RETURN 0
GO

--------------

Dim MyConnection As SqlConnection
Dim MyConnection As SqlCommand

MyConnection = New SqlConnection(sqlconn)
MyCommand = new SqlCommand("sp_CheckNetName", MyConnection)
MyCommand.CommandType = CommandType.StoredProcedure

MyCommand.Parameters.Add("@CID", SqlDbType.int, 4)
MyCommand.Parameters("@CID").Value = Trim(request("COMPID"))

MyCommand.Parameters.Add("@Netname", SqlDbType.VarChar, 25)
MyCommand.Parameters("@Netname").Value = Trim(netname.text)

MyCommand.Parameters.Add("@Return", SqlDbType.Int, 4)
MyCommand.Parameters("@Return").Direction = ParameterDirection.ReturnValue;


sqlconn.Open();
MyCommand.ExecuteNonQuery();
sqlconn.Dispose();
results.Text = MyDataAdapter.SelectCommand.Parameters(2).Value;


There is no need to use a DataAdapter here. Just execute the command directly. Also, although I have not changed it in the code above, refrain from using "sp_" as a prefix for stored procedures as SQL Server will look for the procedure in the Master DB before looking in your database, causing a slight degredation in performance.
--
Edd Connolly

MCP 70-315

"David Lozzi" <dlozzi(remove-this)@delphi-ts.com> wrote in message news:eE**************@TK2MSFTNGP10.phx.gbl...
Here is the proc:

CREATE PROCEDURE [dbo].[sp_CheckNetName]
@CID as int,
@Netname as nvarchar(25),
@Return as int OUTPUT
AS
IF EXISTS (SELECT DISTINCT netname FROM computers WHERE CompanyID = @CID AND UPPER(netname) = UPPER(@Netname))
SELECT @Return = 1
ELSE
SELECT @Return = 0
GO

Which this works great in query analyzer.... Now here is the ASP.NET script to load this proc:

Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyDataAdapter As SqlDataAdapter

MyConnection = New SqlConnection(sqlconn)
MyDataAdapter = New SqlDataAdapter("sp_CheckNetName", MyConnection)
MyDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure

MyDataAdapter.SelectCommand.Parameters.Add(New SqlParameter("@CID", SqlDbType.int, 4))
MyDataAdapter.SelectCommand.Parameters("@CID").Val ue = Trim(request("COMPID"))

MyDataAdapter.SelectCommand.Parameters.Add(New SqlParameter("@Netname", SqlDbType.VarChar, 25))
MyDataAdapter.SelectCommand.Parameters("@Netname") .Value = Trim(netname.text)

MyDataAdapter.SelectCommand.Parameters.Add(New SqlParameter("@Return", SqlDbType.Int, 4))
MyDataAdapter.SelectCommand.Parameters("@Return"). Direction = ParameterDirection.Output

DS = New DataSet()
MyDataAdapter.Fill(DS, "Net")

results.Text = MyDataAdapter.SelectCommand.Parameters(2).Value

MyDataAdapter.Dispose()
MyConnection.Close()

The results always displays 0, however in queryanalyzer, it will display the appropriate response.

Thanks!

--
David Lozzi
Web Applications/Network Specialist
Delphi Technology Solutions, Inc.
dlozzi(remove-this)@delphi-ts.com
Nov 18 '05 #5
Just shoot me now!!! I was sending the wrong variable to the CID...

thanks for your help!!

--
David Lozzi
Web Applications/Network Specialist
Delphi Technology Solutions, Inc.
dlozzi(remove-this)@delphi-ts.com
"David Lozzi" <dlozzi(remove-this)@delphi-ts.com> wrote in message news:ub**************@TK2MSFTNGP12.phx.gbl...
No such luck. First off, I believe you were writing in jscript? I had to remove the ;. I am getting the same results, it is only returning 0. Here's the new proc:

CREATE PROCEDURE [dbo].[sp_CheckNetName]
@CID as int,
@Netname as nvarchar(25)
AS

IF EXISTS (SELECT DISTINCT netname FROM computers WHERE CompanyID = @CID AND UPPER(netname) = UPPER(@Netname))
Return 1
ELSE
Return 0
GO

And here is what my VB looks like now:

sub checkNetName(sender as object, e as eventargs)
Dim MyConnection As SqlConnection
Dim MyCommand As SqlCommand

MyConnection = New SqlConnection(sqlconn)
MyCommand = new SqlCommand("sp_CheckNetName", MyConnection)
MyCommand.CommandType = CommandType.StoredProcedure

MyCommand.Parameters.Add("@CID", SqlDbType.int, 4)
MyCommand.Parameters("@CID").Value = Trim(request("COMPID"))

MyCommand.Parameters.Add("@Netname", SqlDbType.VarChar, 25)
MyCommand.Parameters("@Netname").Value = Trim(netname.text)

MyCommand.Parameters.Add("@Return", SqlDbType.Int, 4)
MyCommand.Parameters("@Return").Direction = ParameterDirection.ReturnValue

myconnection.Open()
MyCommand.ExecuteNonQuery()
myconnection.Dispose()
results.Text = MyCommand.Parameters(2).Value
end sub
Could it be the EXISTS? Is there another way of checking to see if a value is contained in a table?

THANKS!
--
David Lozzi
Web Applications/Network Specialist
Delphi Technology Solutions, Inc.
dlozzi(remove-this)@delphi-ts.com
"Edd Connolly" <ed******************@hotmail.com> wrote in message news:si****************@newsfe3-gui.ntli.net...
David,

The last line should have read:

results.Text = MyCommand.Parameters(2).Value;
--
Edd Connolly

MCP 70-315

"Edd Connolly" <ed******************@hotmail.com> wrote in message news:Je*****************@newsfe3-gui.ntli.net...
David,

This might help...
CREATE PROCEDURE [dbo].[sp_CheckNetName]
(
@CID int,
@Netname nvarchar(25)
)
AS
IF EXISTS (SELECT DISTINCT netname FROM computers WHERE CompanyID = @CID AND UPPER(netname) = UPPER(@Netname))
RETURN 1
ELSE
RETURN 0
GO

--------------

Dim MyConnection As SqlConnection
Dim MyConnection As SqlCommand

MyConnection = New SqlConnection(sqlconn)
MyCommand = new SqlCommand("sp_CheckNetName", MyConnection)
MyCommand.CommandType = CommandType.StoredProcedure

MyCommand.Parameters.Add("@CID", SqlDbType.int, 4)
MyCommand.Parameters("@CID").Value = Trim(request("COMPID"))

MyCommand.Parameters.Add("@Netname", SqlDbType.VarChar, 25)
MyCommand.Parameters("@Netname").Value = Trim(netname.text)

MyCommand.Parameters.Add("@Return", SqlDbType.Int, 4)
MyCommand.Parameters("@Return").Direction = ParameterDirection.ReturnValue;


sqlconn.Open();
MyCommand.ExecuteNonQuery();
sqlconn.Dispose();
results.Text = MyDataAdapter.SelectCommand.Parameters(2).Value;


There is no need to use a DataAdapter here. Just execute the command directly. Also, although I have not changed it in the code above, refrain from using "sp_" as a prefix for stored procedures as SQL Server will look for the procedure in the Master DB before looking in your database, causing a slight degredation in performance.
--
Edd Connolly

MCP 70-315

"David Lozzi" <dlozzi(remove-this)@delphi-ts.com> wrote in message news:eE**************@TK2MSFTNGP10.phx.gbl...
Here is the proc:

CREATE PROCEDURE [dbo].[sp_CheckNetName]
@CID as int,
@Netname as nvarchar(25),
@Return as int OUTPUT
AS
IF EXISTS (SELECT DISTINCT netname FROM computers WHERE CompanyID = @CID AND UPPER(netname) = UPPER(@Netname))
SELECT @Return = 1
ELSE
SELECT @Return = 0
GO

Which this works great in query analyzer.... Now here is the ASP.NET script to load this proc:

Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyDataAdapter As SqlDataAdapter

MyConnection = New SqlConnection(sqlconn)
MyDataAdapter = New SqlDataAdapter("sp_CheckNetName", MyConnection)
MyDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure

MyDataAdapter.SelectCommand.Parameters.Add(New SqlParameter("@CID", SqlDbType.int, 4))
MyDataAdapter.SelectCommand.Parameters("@CID").Val ue = Trim(request("COMPID"))

MyDataAdapter.SelectCommand.Parameters.Add(New SqlParameter("@Netname", SqlDbType.VarChar, 25))
MyDataAdapter.SelectCommand.Parameters("@Netname") .Value = Trim(netname.text)

MyDataAdapter.SelectCommand.Parameters.Add(New SqlParameter("@Return", SqlDbType.Int, 4))
MyDataAdapter.SelectCommand.Parameters("@Return"). Direction = ParameterDirection.Output

DS = New DataSet()
MyDataAdapter.Fill(DS, "Net")

results.Text = MyDataAdapter.SelectCommand.Parameters(2).Value

MyDataAdapter.Dispose()
MyConnection.Close()

The results always displays 0, however in queryanalyzer, it will display the appropriate response.

Thanks!

--
David Lozzi
Web Applications/Network Specialist
Delphi Technology Solutions, Inc.
dlozzi(remove-this)@delphi-ts.com
Nov 18 '05 #6
David,

Glad you sorted your problem. Apologies for putting a semicolon after my line of VB code. I develop in C# mostly so it's just habit.
--
Edd Connolly

MCP 70-315

"David Lozzi" <dlozzi(remove-this)@delphi-ts.com> wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl...
Just shoot me now!!! I was sending the wrong variable to the CID...

thanks for your help!!

--
David Lozzi
Web Applications/Network Specialist
Delphi Technology Solutions, Inc.
dlozzi(remove-this)@delphi-ts.com
"David Lozzi" <dlozzi(remove-this)@delphi-ts.com> wrote in message news:ub**************@TK2MSFTNGP12.phx.gbl...
No such luck. First off, I believe you were writing in jscript? I had to remove the ;. I am getting the same results, it is only returning 0. Here's the new proc:

CREATE PROCEDURE [dbo].[sp_CheckNetName]
@CID as int,
@Netname as nvarchar(25)
AS

IF EXISTS (SELECT DISTINCT netname FROM computers WHERE CompanyID = @CID AND UPPER(netname) = UPPER(@Netname))
Return 1
ELSE
Return 0
GO

And here is what my VB looks like now:

sub checkNetName(sender as object, e as eventargs)
Dim MyConnection As SqlConnection
Dim MyCommand As SqlCommand

MyConnection = New SqlConnection(sqlconn)
MyCommand = new SqlCommand("sp_CheckNetName", MyConnection)
MyCommand.CommandType = CommandType.StoredProcedure

MyCommand.Parameters.Add("@CID", SqlDbType.int, 4)
MyCommand.Parameters("@CID").Value = Trim(request("COMPID"))

MyCommand.Parameters.Add("@Netname", SqlDbType.VarChar, 25)
MyCommand.Parameters("@Netname").Value = Trim(netname.text)

MyCommand.Parameters.Add("@Return", SqlDbType.Int, 4)
MyCommand.Parameters("@Return").Direction = ParameterDirection.ReturnValue

myconnection.Open()
MyCommand.ExecuteNonQuery()
myconnection.Dispose()
results.Text = MyCommand.Parameters(2).Value
end sub
Could it be the EXISTS? Is there another way of checking to see if a value is contained in a table?

THANKS!
--
David Lozzi
Web Applications/Network Specialist
Delphi Technology Solutions, Inc.
dlozzi(remove-this)@delphi-ts.com
"Edd Connolly" <ed******************@hotmail.com> wrote in message news:si****************@newsfe3-gui.ntli.net...
David,

The last line should have read:

results.Text = MyCommand.Parameters(2).Value;
--
Edd Connolly

MCP 70-315

"Edd Connolly" <ed******************@hotmail.com> wrote in message news:Je*****************@newsfe3-gui.ntli.net...
David,

This might help...
CREATE PROCEDURE [dbo].[sp_CheckNetName]
(
@CID int,
@Netname nvarchar(25)
)
AS
IF EXISTS (SELECT DISTINCT netname FROM computers WHERE CompanyID = @CID AND UPPER(netname) = UPPER(@Netname))
RETURN 1
ELSE
RETURN 0
GO

--------------

Dim MyConnection As SqlConnection
Dim MyConnection As SqlCommand

MyConnection = New SqlConnection(sqlconn)
MyCommand = new SqlCommand("sp_CheckNetName", MyConnection)
MyCommand.CommandType = CommandType.StoredProcedure

MyCommand.Parameters.Add("@CID", SqlDbType.int, 4)
MyCommand.Parameters("@CID").Value = Trim(request("COMPID"))

MyCommand.Parameters.Add("@Netname", SqlDbType.VarChar, 25)
MyCommand.Parameters("@Netname").Value = Trim(netname.text)

MyCommand.Parameters.Add("@Return", SqlDbType.Int, 4)
MyCommand.Parameters("@Return").Direction = ParameterDirection.ReturnValue;


sqlconn.Open();
MyCommand.ExecuteNonQuery();
sqlconn.Dispose();
results.Text = MyDataAdapter.SelectCommand.Parameters(2).Value;


There is no need to use a DataAdapter here. Just execute the command directly. Also, although I have not changed it in the code above, refrain from using "sp_" as a prefix for stored procedures as SQL Server will look for the procedure in the Master DB before looking in your database, causing a slight degredation in performance.
--
Edd Connolly

MCP 70-315

"David Lozzi" <dlozzi(remove-this)@delphi-ts.com> wrote in message news:eE**************@TK2MSFTNGP10.phx.gbl...
Here is the proc:

CREATE PROCEDURE [dbo].[sp_CheckNetName]
@CID as int,
@Netname as nvarchar(25),
@Return as int OUTPUT
AS
IF EXISTS (SELECT DISTINCT netname FROM computers WHERE CompanyID = @CID AND UPPER(netname) = UPPER(@Netname))
SELECT @Return = 1
ELSE
SELECT @Return = 0
GO

Which this works great in query analyzer.... Now here is the ASP.NET script to load this proc:

Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyDataAdapter As SqlDataAdapter

MyConnection = New SqlConnection(sqlconn)
MyDataAdapter = New SqlDataAdapter("sp_CheckNetName", MyConnection)
MyDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure

MyDataAdapter.SelectCommand.Parameters.Add(New SqlParameter("@CID", SqlDbType.int, 4))
MyDataAdapter.SelectCommand.Parameters("@CID").Val ue = Trim(request("COMPID"))

MyDataAdapter.SelectCommand.Parameters.Add(New SqlParameter("@Netname", SqlDbType.VarChar, 25))
MyDataAdapter.SelectCommand.Parameters("@Netname") .Value = Trim(netname.text)

MyDataAdapter.SelectCommand.Parameters.Add(New SqlParameter("@Return", SqlDbType.Int, 4))
MyDataAdapter.SelectCommand.Parameters("@Return"). Direction = ParameterDirection.Output

DS = New DataSet()
MyDataAdapter.Fill(DS, "Net")

results.Text = MyDataAdapter.SelectCommand.Parameters(2).Value

MyDataAdapter.Dispose()
MyConnection.Close()

The results always displays 0, however in queryanalyzer, it will display the appropriate response.

Thanks!

--
David Lozzi
Web Applications/Network Specialist
Delphi Technology Solutions, Inc.
dlozzi(remove-this)@delphi-ts.com
Nov 18 '05 #7

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

Similar topics

4
by: Michael Trosen | last post by:
Hi Everyone, I hope someone can help, I'm pretty new to pro*c programming. I have the following application setup: a pro*c program calls a stored procedure and recieves a cursor back: the...
1
by: Robin Hammond | last post by:
Can anybody tell me why a) when running a stored proc from an asp page to return a recordset the command succeeds if the sp queries an existing table directly, but b) if the stored proc populates...
4
by: Jacques Wentworth | last post by:
Hi I have the following problem. I have a SQL Server (2000) Stored Proc that with 4 parameter (one being @UnlockKey uniqueidentifier OUTPUT). I run it from Query Analyzer and the @Key parameter...
5
by: Paul Aspinall | last post by:
Hi I have a Stored Proc in SQL server, which creates a record key when a record is created. I want to return the value back to my code, once the record has been created. I am using SQLHelper...
4
by: Andrew Baker | last post by:
I have the following code that calles a stored proc in SQLServer. When the output parameter @custref is null (System.DBNull) I cant seem to find a test for this and I get an exception. I know I...
1
by: Phil Mc | last post by:
Trying to call a stored proc but some times don't want to have values inserted in some fields. Hi I am rewriting a VBS script which called a stored proc in a SQL server db. The proc takes a...
2
by: jzogg7272 | last post by:
In my code I am executing a stored procedure to do a single row insert. I check the return value of the execution and I am getting -1, whereas a few weeks ago it was returning 0. Actually, I found...
3
by: bogdan | last post by:
Hi, I have a stored procedure that returns a single value. Example: SELECT @RowCount = COUNT(*) FROM t WHERE RETURN @RowCount I created a data set, table adapter, and adapter's method...
3
by: codefragment | last post by:
Hi I have a chunky bit of sql that I will want to call from a number of places. It will return a few thousand rows. Whats the best way of structuring this? 1) I initially thought of using...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.