Showing posts with label developing. Show all posts
Showing posts with label developing. Show all posts

Saturday, March 24, 2012

passing 30+ parameters

i am developing a asp.net aplication, in that..Form1 has some 30 plus text input boxes.

i use a business logic to insert data into the database,

What will be the optimal way to pass all these parameters to BusinessLogic in a single function call?

Hi

I create a structure and fill up the details and then pass it to the business logic and this works very well for me.

I suggest, you try this approach.


Usually for most of my web apps I create a data access layer (DAL) that is a seperate DLL.

I have all my data modelled in objects and pass only the objects back and forth to the DAL. I sometime mix in the business logic layer (BLL) into the DAL as well depending on how complex the application is. One advantage to this is it is quite easy to slap on any type of a GUI onto you application since the core of the application lives is in the DAL or DAL & BLL.

It will make your life easier maintaining the code in the future as well.


so is it advicable to send them in object arrays

Yes.

You could use generics (templates) to pass them if you like.

List<yourObject> type.


sorry, i dont follow your last post. can you give a sample for say 6 diferrent objects

You can use something like the following:

List<String> myStringList = new List<String>();

myStringList.Add("String1");

myStringList.Add("String2");

Generic type will ensure that you are only inserting the String and not any other object. If you have different objects that you will be inserting you can use an ArrayList or better off List<object>.


List<String> myStringList = new List<String>();

myStringList.Add("Alpha");

myStringList.Add("11 Address");

what is the <String> there?Tongue Tied


String is a type. List<String> means that you are creating a list which will only contain string elements. So, if you have 30 textboxes you can iterate through the textboxes and populate the list. Later if you need to access the values of the textboxes you can put the list into a session variable and then access it on the next page.


List<String> myStringList = new List<String>();

creates a "container" called myStringList which can only host String object. You can put as many String object as you want and pass the List "container" itself as parameter. here is one example.

public ... function (List<string> inputList)
{
...

foreach (string currValue in inputList)
{
// iterate through the List

// Do something

}


return ...;
}


Is the List<String> objectIndexed.

How do i access the individual objects in the list?


It's very simple:

List<string> lstStrings = new List<string>();

lstStrings.Add("Test");

string sTemp = lstStrings[0];

or you could use a foreach

foreach (string sTemp in lstStrings)...


List<string> lstStrings = new List<string>();

i get this error when trying to use that construct

"Error 1 The type or namespace name 'List' could not be found (are you missing a using directive or an assembly reference?)"


add this to the top of your code behind file:

using System.Collections.Generic;


using System.Collections.Generic;using System.Collections.Generic;add this to the top of your code behind file:

using System.Collections.Generic;

Friday, March 16, 2012

Passing a Variable

Ok here I go again, I am for the most part a novice with ASP.NET. I have an FAQ Knowledge base system that I am currently developing. The basics of it are as follows:

Data is stored on SQL DB, Tables have not been created but the tables will be set up accordingly when I reach that stage. THey will contain the information to display to the user querying the system for answers.

Now to the meat of it, and I may be thinking to hard on the steps to make it work but this is what I have come up with to impliment. Basic page that has a menu driven system I guess similiar to MSDN menu system.

//menu
////category1
////////topic1
////////topic2
////////topic3
////////topic4
////category2
////////topic1
////////topic2
////////topic3
////////topic4

Each menu item will target an iframe to the right of it, again similair to MSDN. here is where my dilema comes into play.

I could just create a static page for each menu item and have it target the iframe, but that would defeat the dynamic function of it, not to mention way to much data to enter when I could just enter it once into the DB for uses beyond the FAQ Knowledge base system.

So I was thinking I have asp.net page that is the source for the iframe i.e. [iframe name="faq" src="http://pics.10026.com/?src=faq.aspx"][/iframe]

This faq.aspx would be such that it would maintain the DB connection string and dataset and so forth for actually displaying the data queryed from the DB and each menu item somehow pass a value that when clicked would load the faq.aspx with the value it is and perform a select statment on the DB based upon the value that it was predifined with.

i.e.

//menu
////category1
////////topic1 = 1_1

sending the value 1_1 to the page_load() event where a select statement would query database with value that is 1_1
where 1_1 = topic_id 1234

I guess here is a my idea of what the code could look like

Sub Page_Load()

Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyCommand As SqlDataAdapter

Dim SelectCommand As String = "select * from DB where topic_id = @dotnet.itags.org.topic_id"

MyConnection = New SqlConnection()
MyConnection.ConnectionString="my connection string"
MyCommand = New SqlDataAdapter(SelectCommand, MyConnection)

MyCommand.SelectCommand.Parameters.Add(New SqlParameter("@dotnet.itags.org.topic_id", SqlDbType.Int, 4))
MyCommand.SelectCommand.Parameters("@dotnet.itags.org.topic_id").Value = passedvariable??

DS = new DataSet()
MyCommand.Fill(ds, "DB")

MyDataGrid.DataSource=ds.Tables("DB").DefaultView
MyDataGrid.DataBind()

End Sub

Or something like that. I hope I am getting my point across, my question is how to get that passed variable over to that select statment. I know how to do the select statement just not getting the variable to it. Any suggestions would be a great help.You'll want to pass a parameter in the URL. For example faq.aspx?id=1234

Then you can read it in your code by access the Request.QueryString collection:

MyCommand.SelectCommand.Parameters("@.topic_id").Value = Request.QueryString("id")