Adding Parameters to Access Queries

by Admin 6. October 2009 21:31

Option 1:

Create a Parameter object and add this to an existing Command object.

'Create a new parameter

Dim myParam As New OleDbParameter("ParamName", paramValue)

'add the parameter to the command

cmd.Parameters.Add(myParam)

Option 2:

Use the AddWithValue option to add a Parameter directly to the Command object.

'create, assign value and add a new parameter to the command

cmd.Parameters.AddWithValue("ParamName", paramValue)

 

Tags: , ,

Access

Adding Parameters to SQL Server Queries

by CameronM 6. October 2009 21:23

Option 1:

Create a new Parameter object for each parameter required in the SQL query or Stored Procedure.

//Create a new command object

SqlCommand cmd = new SqlCommand();

 

//Create a new parameter

SqlParameter param = new SqlParameter("@parameterName", paramValue);

 

//add the parameter to the command

cmd.Parameters.Add(param);

Option 2:

Use the AddWithValue, to create Parameter and assign a value to a Command object.

//Create a new command object

SqlCommand cmd = new SqlCommand();

 

//add the parameter to the command

cmd.Parameters.AddWithValue("@parameterName", paramValue);

Tags: , , , , , ,

SQL Server | SQL Server