473,763 Members | 1,333 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Creating a function

Hi,

This is causing me a few problems as I am not sure how to handle this...

I have a data access layer. My layer is built in such a way that I can use
any database type I choose, such as SQL Server, MySQL etc.

Now, in my layer, I have all my SQL statements and use parameterised
queries. An example of a parameter is...

cmd = DL.CreateComman d(sql, conn);

param = DL.CreateDataPa rameter();
param.Parameter Name = "@DomainNam e";
param.DbType = DbType.String;
param.Value = DomainName;

cmd.Parameters. Add(param);

(DL is the data layer)

What I would like to do somehow is to call a function and pass the values,
but I am not sure how the function should be constructed.

I want to be able to call it something like...

param = BuildParam("@Do mainName", DbType.String, ValueString).

The reason being is my Datalayer is getting quite big now, much of the space
is taken by declaring my parameters like what is shown.

Any help would be appreciated.

BTW. Thanks Alexei, the keys in my web.config to allow authentication across
applications worked great.

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
Apr 5 '07 #1
3 1345
Something like this is how I might do it (this is untested "Pseudocode "):

public IDbCommand AddParameter(ID bCommand cmd, string paramName, DbType
paramType, object paramValue )
{

IDataParameter param = new (whatever the database provider is, e.g.
SqlParameter)
param.Name = paramName;
param.DbType = paramType;
param.Value =paramValue;
cmd.Parameters. Add(param)
return cmd;
}

http://msdn2.microsoft.com/en-us/lib...rs(vs.71).aspx

Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"David" wrote:
Hi,

This is causing me a few problems as I am not sure how to handle this...

I have a data access layer. My layer is built in such a way that I can use
any database type I choose, such as SQL Server, MySQL etc.

Now, in my layer, I have all my SQL statements and use parameterised
queries. An example of a parameter is...

cmd = DL.CreateComman d(sql, conn);

param = DL.CreateDataPa rameter();
param.Parameter Name = "@DomainNam e";
param.DbType = DbType.String;
param.Value = DomainName;

cmd.Parameters. Add(param);

(DL is the data layer)

What I would like to do somehow is to call a function and pass the values,
but I am not sure how the function should be constructed.

I want to be able to call it something like...

param = BuildParam("@Do mainName", DbType.String, ValueString).

The reason being is my Datalayer is getting quite big now, much of the space
is taken by declaring my parameters like what is shown.

Any help would be appreciated.

BTW. Thanks Alexei, the keys in my web.config to allow authentication across
applications worked great.

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
Apr 5 '07 #2
This style of coding may help streamline:
Sub Dothis(byVal DomainName As String, byVal Something As Integer)

....

With cmd.Parameters
.Add(New SqlParameter("@ DomainName", DomainName))
.Add(New SqlParameter("@ Something", Something))
End With

....

End sub
Apr 5 '07 #3
Fantastic. This lead me onto....

in my calling location
cmd.Parameters. Add(AddParamete r(DL.CreateData Parameter(), cmd,
"@DomainNam e", DbType.String, DomainName));

public IDataParameter AddParameter(ID ataParameter param, IDbCommand cmd,
string paramName, DbType paramType, object paramValue )
{
param.Parameter Name = paramName;
param.DbType = paramType;
param.Value =paramValue;
return param;
}

Looking at this, I can remove the cmd portion as well.

Once I understood this, I then went further using your code more closely
(where I need the cmd portion)

cmd = AddParameter(DL , cmd, "@DomainNam e", DbType.String, DomainName);

public IDbCommand AddParameter(Da taAccessLayer.P roviderFactory DL,
IDbCommand cmd, string paramName, DbType paramType, object paramValue )
{

IDataParameter param = DL.CreateDataPa rameter();
param.Parameter Name = paramName;
param.DbType = paramType;
param.Value =paramValue;
cmd.Parameters. Add(param);

return cmd;
}
Thanks.

I am gonna have a big job now re-writing my code to use this...

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
"Peter Bromberg [C# MVP]" <pb*******@yaho o.yabbadabbadoo .comwrote in
message news:70******** *************** ***********@mic rosoft.com...
Something like this is how I might do it (this is untested "Pseudocode "):

public IDbCommand AddParameter(ID bCommand cmd, string paramName, DbType
paramType, object paramValue )
{

IDataParameter param = new (whatever the database provider is, e.g.
SqlParameter)
param.Name = paramName;
param.DbType = paramType;
param.Value =paramValue;
cmd.Parameters. Add(param)
return cmd;
}

http://msdn2.microsoft.com/en-us/lib...rs(vs.71).aspx

Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"David" wrote:
>Hi,

This is causing me a few problems as I am not sure how to handle this...

I have a data access layer. My layer is built in such a way that I can
use
any database type I choose, such as SQL Server, MySQL etc.

Now, in my layer, I have all my SQL statements and use parameterised
queries. An example of a parameter is...

cmd = DL.CreateComman d(sql, conn);

param = DL.CreateDataPa rameter();
param.Parameter Name = "@DomainNam e";
param.DbType = DbType.String;
param.Value = DomainName;

cmd.Parameters. Add(param);

(DL is the data layer)

What I would like to do somehow is to call a function and pass the
values,
but I am not sure how the function should be constructed.

I want to be able to call it something like...

param = BuildParam("@Do mainName", DbType.String, ValueString).

The reason being is my Datalayer is getting quite big now, much of the
space
is taken by declaring my parameters like what is shown.

Any help would be appreciated.

BTW. Thanks Alexei, the keys in my web.config to allow authentication
across
applications worked great.

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available

Apr 5 '07 #4

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

Similar topics

20
3125
by: svend | last post by:
I'm messing with some code here... Lets say I have this array: a1 = ; And I apply slice(0) on it, to create a copy: a2 = a1.slice(0); But this isn't a true copy. If I go a1 = 42, and then alert(a2) I will see 42 there too. I'm doubting, but I was
0
1651
by: James Fortune | last post by:
Here is an example of Access creating a single page PDF file. The text in the textbox is scaled to fit horizontally into a grey box 100 pixels wide that is fontsize pixels high. Clicking the command button creates the pdf file. Be sure to close Acrobat Reader before creating another file with the same name. Form code is followed by module code. No stream compression or pdf linearization is used in this example. Note that the special...
1
3405
by: Dixie | last post by:
I wish to add some fields to an existing table in code. I am using the following code from rkc. CurrentDb.Execute ("ALTER TABLE MyTable ADD MyNewField Text 25") This works , but I need to also set the Required, Allow Zero Length and Indexed attributes. I have tried but keep getting a syntax error. Also, can I set the default value of a field in code? Has anyone some examples of these. TIA
8
5969
by: Nanda | last post by:
hi, I am trying to generate parameters for the updatecommand at runtime. this.oleDbDeleteCommand1.CommandText=cmdtext; this.oleDbDeleteCommand1.Connection =this.oleDbConnection1; this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_ApplicantName", dataset.Tables.Columns.DataType, 50,
15
6750
by: Carlos Lozano | last post by:
Hi, What is the right way to create an OCX COM component. The component is already registerred, but can't create an instance. I am using the reference to the interop module created. If I use javascript or vbscript it works. I will appreciate any help. I do the following (C#):
6
1919
by: Simon Verona | last post by:
I would normally use code such as : Dim Customer as new Customer Dim t as new threading.thread(AddressOf Customer.DisplayCustomer) Customer.CustomerId=MyCustomerId t.start Which would create a new thread to display a customer on the screen for example. However, I have a problem with circular references in my objects which means that I have to load the customer object using reflection ie :
1
2529
by: CES | last post by:
All, I was wondering if someone could point me to a tutorial on creating & accessing functions from within a wrapper function. I've created a group of functions related to a timer event. All works well until I try to enclose these functions into a class like structure ie: function dTimer(div){ //Insert the Javascript Code Below startTimer(); }
17
46557
Motoma
by: Motoma | last post by:
This article is cross posted from my personal blog. You can find the original article, in all its splendor, at http://motomastyle.com/creating-a-mysql-data-abstraction-layer-in-php/. Introduction: The goal of this tutorial is to design a Data Abstraction Layer (DAL) in PHP, that will allow us to ignore the intricacies of MySQL and focus our attention on our Application Layer and Business Logic. Hopefully, by the end of this guide, you will...
2
3324
by: ChrisO | last post by:
I've been pretty infatuated with JSON for some time now since "discovering" it a while back. (It's been there all along in JavaScript, but it was just never "noticed" or used by most until recently -- or maybe I should just speak for myself.) The fact that JSON is more elegant goes without saying, yet I can't seem to find a way to use JSON the way I *really* want to use it: to create objects that can be instantated into multiple...
1
5729
by: kaens | last post by:
So, I have a class that has to retrieve some data from either xml or an sql database. This isn't a problem, but I was thinking "hey, it would be cool if I could just not define the functions for say xml if I'm using sql", so I did some fiddling around with the interpreter. First, I try conditionally creating a function, period: a = 'a'
0
9563
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, 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...
0
9998
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 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...
0
9822
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7366
isladogs
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...
0
6642
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();...
0
5270
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...
1
3917
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
3
3523
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2793
bsmnconsultancy
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...

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.