473,395 Members | 1,987 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,395 software developers and data experts.

User-defined function

I have user-defined function in MSSQL which returns Table (with 10 columns)

(sorry for Polish names)

CREATE FUNCTION PACZKI_Z_AKCJI
(@AKCJA_ID int)
RETURNS TABLE
RETURN
SELECT TOP 100 PERCENT dbo.PACZKI.ID_PACZKI, dbo.PACZKI.ID_AKCJI,
dbo.PACZKI.NR_PACZKI, dbo.PACZKI.ILOSC_KUPONOW, LOG_1.Login AS LOGIN1,
dbo.PACZKI.ID_PAKOWACZA, LOG_2.Login AS LOGIN2,
dbo.PACZKI.ID_S_PAKOWALNI, dbo.PACZKI.DATA_PAKOWANIA
FROM dbo.LOGOWANIE LOG_1 INNER JOIN
dbo.PACZKI ON LOG_1.Osoba_ID = dbo.PACZKI.ID_PAKOWACZA
INNER JOIN
dbo.LOGOWANIE LOG_2 ON dbo.PACZKI.ID_S_PAKOWALNI =
LOG_2.Osoba_ID
WHERE dbo.PACZKI.ID_AKCJI=@AKCJA_ID
ORDER BY dbo.PACZKI.NR_PACZKI

As you can see function has one parameter @AKCJA_ID so function doesn't
return always all rows but only these which I need.

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

NOW - MY PROBLEM

How use that function in VB.DOTNET form?
I have combobox with ACTIONS - where I choose my paramter @AKCJA_ID

and I want then fill datagrid with table returned from user-defined function

QUESTIONS:
1) How connect User-defined function from MSSQL to form in VB.DONTET
2) How pass parameter from combobox to that function?

I found out that I can use dataadapter with command:

select * from paczki_z_akcji (1)

but how change parameter in brackets? (1) <---this should change while I am
changing items in combobox

In help of Microsoft VB.NET i can find that user defined functions are in
server explorer just like stored procedures :)
But there are no user defined functions! Only tables, views and procedures.
Maybe there is solution to return tables in stored procedures? :)
Nov 21 '05 #1
3 4105
Functions *usually* return scalar values... You might consider creating
this as a Stored Procedure. Then you just set up a Parameterized Query in
..NET and use the recordset returned like any other.

Of course if the Function method works, who am I to tell you differently?
To answer your second question, you might try something like this:

Dim i as Integer
i = 1
Dim sqlcmd as New SqlCommand ("select * from paczki_z_akcji (@AKCJA_ID)",
sqlcon)
sqlcmd.Parameters.Add("@AKCJA_ID", SqlDbType.Int).Value = i

One caveat: I've never actually done this with a UDF before, mostly just
with SP's. But hey, give it a shot and see if it works for you. Also
you'll have to change the code to match your variables, SqlCommand,
SqlConnection, etc.

"chreo" <ch***@gazeta.pl> wrote in message
news:d1**********@inews.gazeta.pl...
I have user-defined function in MSSQL which returns Table (with 10 columns)

(sorry for Polish names)

CREATE FUNCTION PACZKI_Z_AKCJI
(@AKCJA_ID int)
RETURNS TABLE
RETURN
SELECT TOP 100 PERCENT dbo.PACZKI.ID_PACZKI, dbo.PACZKI.ID_AKCJI,
dbo.PACZKI.NR_PACZKI, dbo.PACZKI.ILOSC_KUPONOW, LOG_1.Login AS LOGIN1,
dbo.PACZKI.ID_PAKOWACZA, LOG_2.Login AS LOGIN2,
dbo.PACZKI.ID_S_PAKOWALNI, dbo.PACZKI.DATA_PAKOWANIA
FROM dbo.LOGOWANIE LOG_1 INNER JOIN
dbo.PACZKI ON LOG_1.Osoba_ID =
dbo.PACZKI.ID_PAKOWACZA INNER JOIN
dbo.LOGOWANIE LOG_2 ON dbo.PACZKI.ID_S_PAKOWALNI =
LOG_2.Osoba_ID
WHERE dbo.PACZKI.ID_AKCJI=@AKCJA_ID
ORDER BY dbo.PACZKI.NR_PACZKI

As you can see function has one parameter @AKCJA_ID so function doesn't
return always all rows but only these which I need.

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

NOW - MY PROBLEM

How use that function in VB.DOTNET form?
I have combobox with ACTIONS - where I choose my paramter @AKCJA_ID

and I want then fill datagrid with table returned from user-defined
function

QUESTIONS:
1) How connect User-defined function from MSSQL to form in VB.DONTET
2) How pass parameter from combobox to that function?

I found out that I can use dataadapter with command:

select * from paczki_z_akcji (1)

but how change parameter in brackets? (1) <---this should change while I
am changing items in combobox

In help of Microsoft VB.NET i can find that user defined functions are in
server explorer just like stored procedures :)
But there are no user defined functions! Only tables, views and
procedures.
Maybe there is solution to return tables in stored procedures? :)

Nov 21 '05 #2
It still doesn't work... :(

Użytkownik "Michael C#" <xy*@abcdef.com> napisał w wiadomości
news:jE***************@fe08.lga...
Functions *usually* return scalar values... You might consider creating
this as a Stored Procedure. Then you just set up a Parameterized Query in
.NET and use the recordset returned like any other.

Of course if the Function method works, who am I to tell you differently?
To answer your second question, you might try something like this:

Dim i as Integer
i = 1
Dim sqlcmd as New SqlCommand ("select * from paczki_z_akcji (@AKCJA_ID)",
sqlcon)
sqlcmd.Parameters.Add("@AKCJA_ID", SqlDbType.Int).Value = i

One caveat: I've never actually done this with a UDF before, mostly just
with SP's. But hey, give it a shot and see if it works for you. Also
you'll have to change the code to match your variables, SqlCommand,
SqlConnection, etc.

"chreo" <ch***@gazeta.pl> wrote in message
news:d1**********@inews.gazeta.pl...
I have user-defined function in MSSQL which returns Table (with 10
columns)

(sorry for Polish names)

CREATE FUNCTION PACZKI_Z_AKCJI
(@AKCJA_ID int)
RETURNS TABLE
RETURN
SELECT TOP 100 PERCENT dbo.PACZKI.ID_PACZKI, dbo.PACZKI.ID_AKCJI,
dbo.PACZKI.NR_PACZKI, dbo.PACZKI.ILOSC_KUPONOW, LOG_1.Login AS LOGIN1,
dbo.PACZKI.ID_PAKOWACZA, LOG_2.Login AS LOGIN2,
dbo.PACZKI.ID_S_PAKOWALNI, dbo.PACZKI.DATA_PAKOWANIA
FROM dbo.LOGOWANIE LOG_1 INNER JOIN
dbo.PACZKI ON LOG_1.Osoba_ID =
dbo.PACZKI.ID_PAKOWACZA INNER JOIN
dbo.LOGOWANIE LOG_2 ON dbo.PACZKI.ID_S_PAKOWALNI =
LOG_2.Osoba_ID
WHERE dbo.PACZKI.ID_AKCJI=@AKCJA_ID
ORDER BY dbo.PACZKI.NR_PACZKI

As you can see function has one parameter @AKCJA_ID so function doesn't
return always all rows but only these which I need.

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

NOW - MY PROBLEM

How use that function in VB.DOTNET form?
I have combobox with ACTIONS - where I choose my paramter @AKCJA_ID

and I want then fill datagrid with table returned from user-defined
function

QUESTIONS:
1) How connect User-defined function from MSSQL to form in VB.DONTET
2) How pass parameter from combobox to that function?

I found out that I can use dataadapter with command:

select * from paczki_z_akcji (1)

but how change parameter in brackets? (1) <---this should change while I
am changing items in combobox

In help of Microsoft VB.NET i can find that user defined functions are in
server explorer just like stored procedures :)
But there are no user defined functions! Only tables, views and
procedures.
Maybe there is solution to return tables in stored procedures? :)


Nov 21 '05 #3
Did you try it as a stored procedure, and can you post some of your code?
Specifically the part that sets up your SqlCommand?

"chreo" <ch***@gazeta.pl> wrote in message
news:d1**********@inews.gazeta.pl...
It still doesn't work... :(

Użytkownik "Michael C#" <xy*@abcdef.com> napisał w wiadomości
news:jE***************@fe08.lga...
Functions *usually* return scalar values... You might consider creating
this as a Stored Procedure. Then you just set up a Parameterized Query
in .NET and use the recordset returned like any other.

Of course if the Function method works, who am I to tell you differently?
To answer your second question, you might try something like this:

Dim i as Integer
i = 1
Dim sqlcmd as New SqlCommand ("select * from paczki_z_akcji (@AKCJA_ID)",
sqlcon)
sqlcmd.Parameters.Add("@AKCJA_ID", SqlDbType.Int).Value = i

One caveat: I've never actually done this with a UDF before, mostly just
with SP's. But hey, give it a shot and see if it works for you. Also
you'll have to change the code to match your variables, SqlCommand,
SqlConnection, etc.

"chreo" <ch***@gazeta.pl> wrote in message
news:d1**********@inews.gazeta.pl...
I have user-defined function in MSSQL which returns Table (with 10
columns)

(sorry for Polish names)

CREATE FUNCTION PACZKI_Z_AKCJI
(@AKCJA_ID int)
RETURNS TABLE
RETURN
SELECT TOP 100 PERCENT dbo.PACZKI.ID_PACZKI, dbo.PACZKI.ID_AKCJI,
dbo.PACZKI.NR_PACZKI, dbo.PACZKI.ILOSC_KUPONOW, LOG_1.Login AS LOGIN1,
dbo.PACZKI.ID_PAKOWACZA, LOG_2.Login AS LOGIN2,
dbo.PACZKI.ID_S_PAKOWALNI, dbo.PACZKI.DATA_PAKOWANIA
FROM dbo.LOGOWANIE LOG_1 INNER JOIN
dbo.PACZKI ON LOG_1.Osoba_ID =
dbo.PACZKI.ID_PAKOWACZA INNER JOIN
dbo.LOGOWANIE LOG_2 ON dbo.PACZKI.ID_S_PAKOWALNI =
LOG_2.Osoba_ID
WHERE dbo.PACZKI.ID_AKCJI=@AKCJA_ID
ORDER BY dbo.PACZKI.NR_PACZKI

As you can see function has one parameter @AKCJA_ID so function doesn't
return always all rows but only these which I need.

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

NOW - MY PROBLEM

How use that function in VB.DOTNET form?
I have combobox with ACTIONS - where I choose my paramter @AKCJA_ID

and I want then fill datagrid with table returned from user-defined
function

QUESTIONS:
1) How connect User-defined function from MSSQL to form in VB.DONTET
2) How pass parameter from combobox to that function?

I found out that I can use dataadapter with command:

select * from paczki_z_akcji (1)

but how change parameter in brackets? (1) <---this should change while I
am changing items in combobox

In help of Microsoft VB.NET i can find that user defined functions are
in server explorer just like stored procedures :)
But there are no user defined functions! Only tables, views and
procedures.
Maybe there is solution to return tables in stored procedures? :)



Nov 21 '05 #4

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

Similar topics

3
by: zlst | last post by:
Many technological innovations rely upon User Interface Design to elevate their technical complexity to a usable product. Technology alone may not win user acceptance and subsequent marketability....
2
by: Jesper Stocholm | last post by:
I have implemented role-based security within my ASP.Net application. However, it seems the role is not passed to the authentication ticket I create. I want to use it to display/hide some...
5
by: Michelle Stone | last post by:
Hi everybody I am writing a simple asp.net application using form authentication. I store the list of all users and their passwords in an SQL Server database table. My client recently told me...
6
by: martin | last post by:
Hi, I am a web page and a web user control. My web user control is placed in my web page using the following directive <%@ Register TagPrefix="uc1" TagName="Header"...
7
by: jsale | last post by:
I'm currently using ASP.NET with VS2003 and SQL Server 2003. The ASP.NET app i have made is running on IIS v6 and consists of a number of pages that allow the user to read information from the...
0
by: tony | last post by:
Hello! This is a rather long mail but it's a very interesting one. I hope you read it. I have tried several times to get an answer to this mail but I have not get any answer saying something...
2
by: rn5a | last post by:
Assume that a user control (MyUC.ascx) encapsulates 2 TextBoxes with the IDs 'txt1' & 'txt2' respectively. To use this user control in an ASPX page, the following Register directive will be...
1
by: Carlettus | last post by:
Dear All, sorry but I'm not sure if this is the right place to post my problem. I was using the following asp code to create users in Active Directory. Suddenly, and I don't know the reason, users...
0
by: rbukkara | last post by:
Hi, I have got the following error while trying to add a user in the LDAP Directory. javax.naming.NameNotFoundException: ; remaining name 'uid=vassila,ou=People,dc=cs,dc=uno,dc=edu' I have...
3
by: shapper | last post by:
Hello, On my web site I have a property, Visitor, which is available for Anonymous users: public class Visitor { public CultureInfo Culture { get; set; } public List<GuidPolls { get; set;...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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
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...
0
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...

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.