i am trying to create an sql parameter but i am having an error. it gives me an error like this: Unable to cast object of type 'System.Boolean' to type 'System.Data.SqlClient.SqlParameter'. on all of this line

These evaluate from the inside out, so evaluation starts with statement3. This returns a new SqlParameter object. Now statement2 exposes the problem with overloading "=" to mean both assignment and an equality check. It looks like VB believes you are asking, "Does the value of this SqlParameter equal the same value as CGLCode?. VB beleives this because the call to Add in statement1 expects a value, but assignment does not return a value. The equality comparison returns a boolean value. This boolean value is used by statement1, which expects an object of type SqlParameter and fails.

You have four choices to fix this.

You could use multiple lines to create the parameter, then set the value:

Method 1 has lots of repetition and breaks the DRY (Don't Repeat Yourself) principle; you should use method 4 instead of method 1. Method 2 reduces your control over the final type; if the computer makes the wrong guess you could get an unexpected error. Method 3 is a good version of Method 1, but will only work in VB .NET 2008. Method 4 is an improvement over Method 1 as well.

and now... the code works well but my problem is the execution part in my class. i tested the class with simple sql statements without any parameters and it works perfectly. but now when i added a parameter in my sqlstatement, it gives me this kind of error.

not List`1 objects
The "`1" notation is a .NET implementation detail that appears when you are using Generic classes. I believe the full name of List(Of SqlParameter) would appear as List`1SqlParameter in call stacks and other internals.

ByVal cparam As List(Of SqlParameter)
This is the only generic list that your function works with.

cm.Parameters.Add(cparam)
This is the only method that uses the generic list.

The error message indicates that the List type isn't supported by this method; let's look at the documentation. Parameters is of type SqlParameterCollection; here's the Add method overloads. Hmm, notice they are all singular, "Adds a SqlParameter..." The problem is the Add method was made to add only one SqlParameter at a time, and you are trying to add more than one.

Add(Object) seems to imply you can add anything, but if you look through the documentation you see that it only exists because it's defined on the base class DbParameterCollection; the designers should have used an interface rather than inheritance here, and it also shows why generic types were such a fantastic addition to the framework.

Anyway, it's very common for collection classes in .NET to implement two Add methods: Add for adding one object at a time and AddRange for adding multiple objects. SqlParameterCollection.AddRange is what you want. Note that it needs an array (yet another design error; it should have been IEnumerable), so you'll need to call the ToArray method of your list:

Try this instead of the Add call:cm.Parameters.AddRange(cparam.ToArray())

Technically, it would be a better design decision for your cparam parameter to be either an array or IEnumerable instead of a list. IEnumerable(Of SqlParameter) is the most flexible, and it has a ToArray extension method in .NET 3.5. If you aren't using .NET 3.5, you might want to stick to just an array type since the interface to Add is cruddy.