HI,
I am trying to convert the following vba code to c# and i am facing some errors.Hope someone can help me
vba code
Open 'C:\testfile.txt' For Input As #1 varii = '' Do While Not EOF(1) Line Input #1, strField varii = varii & ',' & strField Loop Close #1 astrFields = Split(varii, ',') For intIx = 1 To UBound(astrFields) counter = 0 i = i + 1 Dim cn As New ADODB.Connection, cn2 As New ADODB.Connection Dim rs As ADODB.Recordset Dim connString As String Dim SelectFieldName Set cn = CurrentProject.Connection SelectFieldName = astrFields(intIx) Set rs = cn.OpenSchema(adSchemaColumns, _ Array(Empty, Empty, Empty, SelectFieldName)) If Left(rs!Table_Name, 4) <> 'MSys' And Left(rs!Table_Name, 4) <> 'Abfr ' Then strSql = 'SELECT t.[' & astrFields(intIx) & '], t.fall from [' & rs!Tab le_Name & '] t Inner Join 01UMWELT on t.fall = [01UMWELT].fall ' End If Set rs3 = CurrentDb.OpenRecordset(strSql) Do While Not rs3.EOF With rs3 feedbackmsg = 'Processing ' & rs!Table_Name & ' Record no : ' & .Fields(1) SysCmd acSysCmdSetStatus, feedbackmsg varii = Nz(.Fields(astrFields(intIx)), 'NullValue') If varii = 'NullValue' Then Call .Edit .Fields(astrFields(intIx)) = 888 Call .Update
THis is the c# code so far i have coded
FileInfo theSourceFile = new FileInfo('C:\\csharp\\testfile.txt'); StreamReader reader = theSourceFile.OpenText(); varii = ''; do { text = reader.ReadLine(); varii = varii + ',' + reader.ReadLine(); //Console.WriteLine(text); } while (text != null); string[] split = varii.Split(new Char[] {' '}); foreach (string s in split) { if (s.Trim() != '') Console.WriteLine(s); } int temp = split.GetUpperBound(1); for (intix = 1; intix <= temp; intix++) { counter = 0; i++; ADODB.Connection cn = new ADODB.Connection(); ADODB.Connection cn2 = new ADODB.Connection(); ADODB.Recordset rs; object selectfieldname; //ConnectionClass conDatabase = new ADODB.Connection(); cn.ConnectionString = 'Provider=Microsoft.Jet.OLEDB.4.0;' + 'Data Source='C:\\csharp\\accident_database.mdb';'; rs = cn.OpenSchema(ADODB.SchemaEnum.adSchemaTables, Missing.Value, Missing.Value); if (Microsoft.Vbe.Left(rs.Fields('Table_Name').Value, 4) != 'MSys' && + Microsoft.Vbe.Left(rs.Fields('Table_Name').Value, 4) != 'Abfr') { strsql = 'SELECT t.[' + split(intix) + '],t.fall from [' + rs.Fields('Table_Name').Value + ']' + 't Inner join 01umwelt on t.fall = [01umwelt].fall'; } rs3 = CurrentDB.OpenRecordset(strsql); while (!rs3.EOF) { feedbackmsg = 'Processing' + rs.Fields('Table_Name').Value + 'Record no:' + rs3.Fields(1).Value; SysCmd acSysCmdSetStatus, feecbackmsg; varii = Nz(rs3.Fields(astrfields(intix)).Value, 'NullValue'); if (varii == 'NullValue') { rs3.Edit(); rs3.Fields[astrfields(intix)].Value = 888; rs3.Update();
I am recieving errors in the if statement
if (Microsoft.Vbe.Left(rs.Fields('Table_Name').Value, 4) != 'MSys' && + Microsoft.Vbe.Left(rs.Fields('Table_Name').Value, 4) != 'Abfr')
here Vbe.left is not getting accepted
and secondly in the sql statement following this i get an error split is an variablebut used like method.
Thanks
In converting bear in mind that VBA uses the same operator () for indexes and method calls, whereas C# uses [] for indexes and () for calls to methods.
should be
Try