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

  • Thread starter Patrick Olurotimi Ige
  • Start date
P

Patrick Olurotimi Ige

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();

}


}
 
E

Eliyahu Goldin

myCommand.Parameters["@Username"].Value = strLogonUsr;
myCommand.Parameters["@DateCreated"].Value = System.DateTime.Now;

Note correct use of Now.

Eliyahu
 
P

Patrick Olurotimi Ige

Eliyahu..thanks alot...
When i code VB and C# at the same time i just miss somethings out....!!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top