.NETGURU
SV: I am trying to convert my VB script to C# here are the line that are the culprit
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngdata' list.


=?iso-8859-1?Q?Andr=E9_Colbi=F6rnsen?=
I am by no means a C# expert, but :

1: Aren't you always supposed to use square brackets in C#

parameterSearch SqlParameter = New SqlParameter["@Search",
SqlDbType.NVarChar, 255)];

and also, I though that using the semicolon after each statement was
also standard procedure.

Regards/Halsningar

Andre Colbiornsen
--------------------------------------
Sonnenburg Communications
Bergsgatan 3,
SE-211 54 Malmö
Sweden
Tel.: +46-(0)40-97 78 80
Fax.: +46-(0)40-97 78 80
Mob.: +46-(0)708-97 78 79
Mail: Click here to reveal e-mail address
Web.: www.sonnenburg.se
--------------------------------------
B2B Web agency - Specializing on .Net
--------------------------------------

-----Ursprungligt meddelande-----
Från: Dennis West [mailto:Click here to reveal e-mail address]
Skickat: den 2 juli 2002 09:38
Till: aspngdata
Ämne: [aspngdata] I am trying to convert my VB script to C# here are the
line that are the culprit

I am trying to convert my VB script to C# here are the line that are the
culprit

// in VB the failing line was like this
// Dim parameterSearch As SqlParameter = New
SqlParameter("@Search", SqlDbType.NVarChar, 255)

parameterSearch SqlParameter = New SqlParameter("@Search",
SqlDbType.NVarChar, 255)
parameterSearch.Value = Request.Params("txtSearch");
myCommand.Parameters.Add(parameterPortalID);

Description: An error occurred during the compilation of a resource
required to service this request. Please review the following specific
error details and modify your source code appropriately.

Compiler Error Message: CS1002: ; expected

Source Error:



Line 41: // Dim parameterSearch As SqlParameter = New
SqlParameter("@Search", SqlDbType.NVarChar, 255)

Line 42:

Line 43: parameterSearch SqlParameter = New
SqlParameter("@Search", SqlDbType.NVarChar, 255)

Line 44: parameterSearch.Value Request.Params("txtSearch");

Line 45: myCommand.Parameters.Add(parameterPortalID);

Source File:
D:\Domains\aspalliance.com\dotnetsolutions\PortalCS\SearchModule\SearchA
nnoucements.aspx Line: 43

private void Page_Load(object sender, System.EventArgs e) {

// Search database using the supplied "txtSearch" parameter

// Create Instance of Connection and Command Object

// Create Instance of Connection and Command Object
SqlConnection myConnection = new
SqlConnection(ConfigurationSettings.AppSettings["connectionString"]);
SqlCommand myCommand = new SqlCommand("AnnoucementSearch",
myConnection);

// Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure;

// Add Parameters to SPROC

// in VB the failing line was like this
// Dim parameterSearch As SqlParameter = New
SqlParameter("@Search", SqlDbType.NVarChar, 255)

parameterSearch SqlParameter = New SqlParameter("@Search",
SqlDbType.NVarChar, 255)
parameterSearch.Value = Request.Params("txtSearch");
myCommand.Parameters.Add(parameterPortalID);

// Open the database connection and execute the command
myConnection.Open();
SqlDataReader dr myCommand.ExecuteReader(CommandBehavior.CloseConnection);

// Bind the datareader

MyList.DataSource = dr;
MyList.DataBind();

// Display a message if no results are found
//If (MyList.Items.Count == 0) {
ErrorMsg.Text = "No items matched your query.";
//}

}

For 2002 ASP.NET Solutions & Articles goto:
http://aspalliance.com/dotnetsolutions/

Dennis West
West Design
MS .NET Developer
www. westontheweb.net
Click here to reveal e-mail address

| [aspngdata] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngdata.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives
Reply to this message...
 
    
Brian W. Spolarich
Square brackets [] are used in C# as indexers, both for arrays and collections.

e.g.

char[] vowels = new char[] {'a','e','i','o','u'};
vowels[1] == "e"; // Evaluates true.

using System.Collections;
Hashtable hash = new Hashtable();
hash["Fred"] = "Flintstone";
hash["Barney"] = "Rubble";

Parentheses () are used as grouping operators:

int y = 3 * (2 + 1);
y == 9;

As well as for method calls:

Console.Writeline("Hello world.\n");

And also for typecasting:

char c = "A";
decimal val = (decimal)c; // val is 65;

This is I believe completely identical in syntax to Java and C.

-bws

-----Original Message-----
From: André Colbiörnsen [mailto:Click here to reveal e-mail address]
Sent: Tuesday, July 02, 2002 9:44 AM
To: aspngdata
Subject: [aspngdata] SV: I am trying to convert my VB script to C# here are the line that are the culprit

I am by no means a C# expert, but :

1: Aren't you always supposed to use square brackets in C#

parameterSearch SqlParameter = New SqlParameter["@Search", SqlDbType.NVarChar, 255)];

and also, I though that using the semicolon after each statement was also standard procedure.

Regards/Halsningar

Andre Colbiornsen
--------------------------------------
Sonnenburg Communications
Bergsgatan 3,
SE-211 54 Malmö
Sweden
Tel.: +46-(0)40-97 78 80
Fax.: +46-(0)40-97 78 80
Mob.: +46-(0)708-97 78 79
Mail: Click here to reveal e-mail address
Web.: www.sonnenburg.se
--------------------------------------
B2B Web agency - Specializing on .Net
--------------------------------------

-----Ursprungligt meddelande-----
Från: Dennis West [mailto:Click here to reveal e-mail address]
Skickat: den 2 juli 2002 09:38
Till: aspngdata
Ämne: [aspngdata] I am trying to convert my VB script to C# here are the line that are the culprit

I am trying to convert my VB script to C# here are the line that are the culprit

// in VB the failing line was like this
// Dim parameterSearch As SqlParameter = New SqlParameter("@Search", SqlDbType.NVarChar, 255)

parameterSearch SqlParameter = New SqlParameter("@Search", SqlDbType.NVarChar, 255)
parameterSearch.Value = Request.Params("txtSearch");
myCommand.Parameters.Add(parameterPortalID);

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1002: ; expected

Source Error:



Line 41: // Dim parameterSearch As SqlParameter = New SqlParameter("@Search", SqlDbType.NVarChar, 255)

Line 42:

Line 43: parameterSearch SqlParameter = New SqlParameter("@Search", SqlDbType.NVarChar, 255)

Line 44: parameterSearch.Value = Request.Params("txtSearch");

Line 45: myCommand.Parameters.Add(parameterPortalID);

Source File: D:\Domains\aspalliance.com\dotnetsolutions\PortalCS\SearchModule\SearchAnnoucements.aspx Line: 43

private void Page_Load(object sender, System.EventArgs e) {

// Search database using the supplied "txtSearch" parameter

// Create Instance of Connection and Command Object

// Create Instance of Connection and Command Object
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["connectionString"]);
SqlCommand myCommand = new SqlCommand("AnnoucementSearch", myConnection);

// Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure;

// Add Parameters to SPROC

// in VB the failing line was like this
// Dim parameterSearch As SqlParameter = New SqlParameter("@Search", SqlDbType.NVarChar, 255)

parameterSearch SqlParameter = New SqlParameter("@Search", SqlDbType.NVarChar, 255)
parameterSearch.Value = Request.Params("txtSearch");
myCommand.Parameters.Add(parameterPortalID);

// Open the database connection and execute the command
myConnection.Open();
SqlDataReader dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection);

// Bind the datareader

MyList.DataSource = dr;
MyList.DataBind();

// Display a message if no results are found
//If (MyList.Items.Count == 0) {
ErrorMsg.Text = "No items matched your query.";
//}

}

For 2002 ASP.NET Solutions & Articles goto:
http://aspalliance.com/dotnetsolutions/

Dennis West
West Design
MS .NET Developer
www. westontheweb.net
Click here to reveal e-mail address

| [aspngdata] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngdata.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

| [aspngdata] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngdata.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives
Reply to this message...
 
 
System.Collections.Hashtable
System.Configuration.ConfigurationSettings
System.Console
System.Data.CommandBehavior
System.Data.CommandType
System.Data.SqlClient.SqlCommand
System.Data.SqlClient.SqlConnection
System.Data.SqlClient.SqlDataReader
System.Data.SqlClient.SqlParameter
System.Data.SqlDbType
System.EventArgs




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification