Groups | Blog | Home
all groups > asp.net > february 2005 >

asp.net : System.Data.SqlClient.SqlCommand.Parameters' denotes a 'property' where a 'method' was expected erro


Patrick Olurotimi Ige
2/7/2005 11:22:42 PM

I converted the code below from VB.NET to C# cos i have to add it to a
C# application!!

But i'm getting the error:-

System.Data.SqlClient.SqlCommand.Parameters' denotes a 'property' where
a 'method' was expected

At the lines:-
myCommand.Parameters("@Username").Value = strLogonUsr;
myCommand.Parameters("@DateCreated").Value = Now();

I guess i am missing something can a C# Guru help



private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
string strLogonUsr;

strLogonUsr = Request.ServerVariables["LOGON_USER"];

myconnection = new
SqlConnection("server=(local);database=Wintergreen;integrated
security=true;");

string insertCmd = "insert into survey values (@username,
@DateCreated)";

myCommand = new SqlCommand(insertCmd, myconnection);


//Created new parameters for the SqlCommand object and
//initialize them to the field values.
//Create the parameter for the logon user

myCommand.Parameters.Add(new
SqlParameter("@Username",SqlDbType.VarChar, 50));

//Assigned the value
myCommand.Parameters("@Username").Value = strLogonUsr;



//Created the parameter for the time
myCommand.Parameters.Add(new
SqlParameter("@DateCreated",SqlDbType.DateTime, 8));

//Assign the value as Now()

myCommand.Parameters("@DateCreated").Value = Now();

myCommand.Connection.Open();


try
{
// Execute the command
myCommand.ExecuteNonQuery();

// Report success
Label1.Text = "<b>Thanks for filling Survey!</b>";

}

catch (SqlException exc)
{

// Report error if exist
Label1.Text = exc.Message;
}


finally
//Close the connection no matter what
{
myCommand.Connection.Close();

}


}


*** Sent via Developersdex http://www.developersdex.com ***
Patrick Olurotimi Ige
2/8/2005 3:22:39 AM
Eliyahu..thanks alot...
When i code VB and C# at the same time i just miss somethings out....!!!




*** Sent via Developersdex http://www.developersdex.com ***
Eliyahu Goldin
2/8/2005 10:22:16 AM
myCommand.Parameters["@Username"].Value = strLogonUsr;
myCommand.Parameters["@DateCreated"].Value = System.DateTime.Now;

Note correct use of Now.

Eliyahu

[quoted text, click to view]

AddThis Social Bookmark Button