PDA

Click to See Complete Forum and Search --> : SQLParametersCollection


cim3
Aug 29th, 2002, 05:22 AM
Has anyone used the sqlparameters collection yet??

Having a few problems adding parameters to it. I am passing the collection to a class to get a dataset.
This is the code
Dim oData As New cDB()
Dim oDS As DataSet
Dim oParam As New SqlParameter()
Dim oParamCol As SqlParameterCollection

With oParam
.ParameterName = "@criteria"
.SqlDbType = SqlDbType.VarChar
.Size = 255
.Value = txtSearchBasic.Text.ToString
End With
oParamCol.Add(oParam)
With oParam
.ParameterName = "@type"
.SqlDbType = SqlDbType.VarChar
.Size = 20
If rbSearchProv.Checked = True Then .Value = "Provider"
If rbSearchProp.Checked = True Then .Value = "Property"
If rbSearchSer.Checked = True Then .Value = "Service"
If rbSearchClient.Checked = True Then .Value = "Client"
End With
oParamCol.Add(oParam)

oDS = oData.GetDataSet("BasicSearch", oParamCol)

However it says an instance of oParamCol = nothing. But add New Keyword to SqlParameterCollection and says its not accessible in this context because it is private. Surely collections can be added too and passed about. The only examples on the net have you adding parameters directly to command object.

cim3
Aug 30th, 2002, 03:15 AM
Sorted - for anybody interested basically the sqlparameterscollection is dependant upon a command object and is not something you can create on its own. As I am passing parameters to my class the command object hasn't been created. Anyway got around it by using an object array with my sqlparameters (which u can create without a command object!) in it.

Magiaus
Aug 30th, 2002, 11:38 AM
cmd.Execute ,Array(param1,parram2,parram3) is the oldway i belive it is simular now except you have more execute options and i think ms is pushing the parameter collection