jpavlov
jpavlov

Reputation: 2261

Is this correct syntax for a C# statment

Is this the correct syntax for a C statment. I recieve the following error message in Visual Studios when trying to use it.

intResult = Convert.ToInt32(cmdSelect.Parameters("RETURN_VALUE").Value);
non-invocable memeber of System.Data.SqlClient.SqlCommand.Parameters can not be used as a method.

Can anyone help clear this up.

I am using the following namespaces as well

using System;
using System.Data;
using System.Configuration;
using System.Web.Configuration;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Web.Security;

Upvotes: 0

Views: 127

Answers (5)

Szymon Rozga
Szymon Rozga

Reputation: 18168

Should be:

intResult = Convert.ToInt32(cmdSelect.Parameters["RETURN_VALUE"].Value);

Upvotes: 4

Donald
Donald

Reputation: 1738

Use the [] index operators on Parameters instead of parentheses:

intResult = Convert.ToInt32(cmdSelect.Parameters["RETURN_VALUE"].Value);

Upvotes: 3

Adam Robinson
Adam Robinson

Reputation: 185613

In C#, indexers use square brackets, not parentheses as in VB.NET. This should do the trick:

intResult = Convert.ToInt32(cmdSelect.Parameters["RETURN_VALUE"].Value);

Upvotes: 4

Ryan Christensen
Ryan Christensen

Reputation: 7933

cmdSelect.Parameters["RETURN_VALUE"].Value

indexors are [] in c#, in VB.net they are ()

Upvotes: 2

Frédéric Hamidi
Frédéric Hamidi

Reputation: 262919

You want to use an indexer, not call a function, so you should use square brackets:

intResult = Convert.ToInt32(cmdSelect.Parameters["RETURN_VALUE"].Value);

Upvotes: 5

Related Questions