Or you can reuse the same parameter variable by doing a: myParameter = New Data.SqlClient.SqlParameter
This makes it a different object. On Mar 9, 10:54 pm, "[email protected]" <[email protected]> wrote: > HI > You need to declare another sqlparameter i.e."Dim myParameter2 As New > Data.SqlClient.SqlParameter" for @Parm2, as this is already in the > collection of parameters. > > Gaurav > > On Mar 9, 2:59 am, DM <[email protected]> wrote: > > > I keep getting the "The SqlParameter is already contained by another > > SqlParameterCollection." error, even when adding the > > Parameter.Clear()....Any ideas? Thanks! > > > I get the error on the getds2 function at the Parameters.Add for Parm2 > > > ' Runs first no error: > > > Private Function getds1() As Data.DataSet > > Dim myConnection As New System.Data.SqlClient.SqlConnection > > Dim myAdapter As New System.Data.SqlClient.SqlDataAdapter > > Dim myCommand As New System.Data.SqlClient.SqlCommand > > Dim myParameter As New Data.SqlClient.SqlParameter > > Dim ds1 As New System.Data.DataSet > > > myConnection = mySqlConnection() > > > myCommand.Connection = myConnection > > myCommand.CommandText = "dbo.GetDS1" > > myCommand.CommandType = Data.CommandType.StoredProcedure > > > myParameter.ParameterName = "@Parm1" > > myParameter.Direction = Data.ParameterDirection.Input > > myParameter.SqlDbType = Data.SqlDbType.VarChar > > myParameter.Value = Session("Parm1") > > myCommand.Parameters.Add(myParameter) > > > myConnection.Open() > > myAdapter.SelectCommand = myCommand > > myAdapter.Fill(ds1) > > myCommand.Parameters.Clear() > > myConnection.Close() > > > Return (ds1) > > > End Function > > > Private Function getds2() As Data.DataSet > > Dim myConnection As New System.Data.SqlClient.SqlConnection > > Dim myAdapter As New System.Data.SqlClient.SqlDataAdapter > > Dim myCommand As New System.Data.SqlClient.SqlCommand > > Dim myParameter As New Data.SqlClient.SqlParameter > > Dim ds2 As New System.Data.DataSet > > > myConnection = mySqlConnection() > > > myCommand.Connection = myConnection > > myCommand.CommandText = "dbo.GetDS2" > > myCommand.CommandType = Data.CommandType.StoredProcedure > > > myParameter.ParameterName = "@Parm1" > > myParameter.Direction = Data.ParameterDirection.Input > > myParameter.SqlDbType = Data.SqlDbType.VarChar > > myParameter.Value = Session("Parm2") > > myCommand.Parameters.Add(myParameter) > > > myParameter.ParameterName = "@Parm2" > > myParameter.Direction = Data.ParameterDirection.Input > > myParameter.SqlDbType = Data.SqlDbType.Int > > myParameter.Value = Session("Parm2") > > myCommand.Parameters.Add(myParameter) > > > myConnection.Open() > > myAdapter.SelectCommand = myCommand > > myAdapter.Fill(ds2) > > myConnection.Close() > > > Return (ds2) > > > End Function -- You received this message because you are subscribed to the Google Groups "DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/dotnetdevelopment?hl=en?hl=en or visit the group website at http://megasolutions.net
