Results 1 to 3 of 3

Thread: [2.0] help converting vb to c sharp...

  1. #1

    Thread Starter
    Addicted Member effekt26's Avatar
    Join Date
    Nov 2006
    Posts
    138

    [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

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Addicted Member effekt26's Avatar
    Join Date
    Nov 2006
    Posts
    138

    Re: [2.0] help converting vb to c sharp...

    Quote 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
  •  



Click Here to Expand Forum to Full Width