|
-
Feb 19th, 2007, 11:22 PM
#1
Thread Starter
Addicted Member
[2.0] help converting vb to c sharp...
Greetings,
I have just started learning the C Sharp language, based on what i already know from vb. im currently converting my website to c sharp, just to get a feel for the language, how ever im stuck.
the following vbcode, when converted to c sharp, does not recognise _param as a defined struct.. (eg: not giving any of the properties.)
Code:
'VB Code:
Dim _param As SqlParameter = hashEnum.Value
objCommand.Parameters.Add(_param.ParameterName, _param.ParameterDataType).Value = _param.ParameterValue
//C Sharp Code
SqlParameter _param = hashEnum.Value;
objCommand.Parameters.Add(_param.ParameterName, _param.ParameterDataType).Value = _param.ParameterValue;
when i go to type _param. i get no intellisense about the properties...
and the entire code block...
Code:
private string connectionString = "";
private SqlConnection objConnection = new SqlConnection(connectionString);
private DataSet dtaSet;
public struct SqlParameter {
private string _name;
private string _value;
private SqlDbType _dataType;
public SqlParameter(string Name, string Value, string DataType) {
_name = Name;
_value = Value;
_dataType = DataType;
}
}
public DataSet ReturnDataSet(string Query, Hashtable Parameters) {
dtaSet = new DataSet();
try {
SqlCommand objCommand = new SqlCommand(Query, objConnection);
if (objCommand.Connection.State != ConnectionState.Open) {
objCommand.Connection.Open();
}
IDictionaryEnumerator hashEnum = Parameters.GetEnumerator;
while (hashEnum.MoveNext) {
SqlParameter _parameter = hashEnum.Value;
objCommand.Parameters.Add();
}
SqlDataAdapter adp = new SqlDataAdapter(objCommand);
adp.Fill(dtaSet);
objConnection.Close;
}
catch (Exception e) {
}
}
can anyone help,
Thanks, Justin
-
Feb 20th, 2007, 12:00 AM
#2
Re: [2.0] help converting vb to c sharp...
I would guess that's because there already exists an SqlParameter class. You've created a name clash. I can't see why you need your SqlParameter structure by any name though. Just create an System.Data.SqlClient.SqlParameter object directly.
-
Feb 20th, 2007, 12:07 AM
#3
Thread Starter
Addicted Member
Re: [2.0] help converting vb to c sharp...
 Originally Posted by jmcilhinney
I would guess that's because there already exists an SqlParameter class. You've created a name clash. I can't see why you need your SqlParameter structure by any name though. Just create an System.Data.SqlClient.SqlParameter object directly.
Oh, i see. but then how come it ran fine with VB?
is VB a little more lax regarding duplicate names??
Thanks, i will use the System.Data.SqlClient.SqlParameter object instead...
Thanks, Justin
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|