none
I have a class RRS feed

  • Question

  • Hi all,

    Below code is written in  c#, I need this code into vb.net, anybody can convert.

    I tried at my side but getting errors.

    Thanks

    <code>

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Collections;
    using System.Data;
    using System.Configuration;
    using System.Data.OleDb;

    namespace project
    {
        interface bbank
        {
            void Select(string query, string tablename);
            void Insert(string query);
            void Delete(string query);
            void Update(string query);
            string cnfrm_username_password(string name, string password);
        
        }

        abstract class bank : bbank
        {
            public OleDbConnection conn = new OleDbConnection();
            public OleDbDataAdapter dadapt = new OleDbDataAdapter();
            public DataSet dset = new DataSet();
            public abstract void Select(string query, string tablename);
            public abstract void Insert(string query);
            public abstract void Delete(string query);
            public abstract void Update(string query);
            public abstract string cnfrm_username_password(string name, string password);
            public static string username;
            public static string password;
        }

        class Parent : bank
        {

         public Parent()
            {
                conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\Database.mdb";
                conn.ConnectionString = "";
                
             conn.Open();
            }

            public override void Select(string query, string tablename)
            {
                dadapt = new OleDbDataAdapter(query, conn);
                dadapt.Fill(dset, tablename);
            }

            public override void Insert(string query)
            {
                OleDbCommand comd = new OleDbCommand(query, conn);
                comd.ExecuteNonQuery();
            }

            public override void Delete(string query)
            {
                OleDbCommand comd = new OleDbCommand(query, conn);
                comd.ExecuteNonQuery();
            }

            public override  void Update(string query)
            {
                OleDbCommand comd = new OleDbCommand(query, conn);
                comd.ExecuteNonQuery();
            }


            public override string cnfrm_username_password(string name, string password)
            {
                foreach (DataRow row in dset.Tables["Login"].Rows)
                {
                    string n = row["User"].ToString();
                    string p = row["Password"].ToString();
                    if (name == n && p == password)
                    {
                        bank.username = n;
                        bank.password = p;
                        return "match";
                        
                    }
             
                }
                return "notmatch";
            }
        }
    }

    </code>

    Thursday, May 3, 2012 10:08 AM

Answers

  • I see one line that is incorrect:

    Public MustOverride Function cnfrm_username_password(name As String, password As String) As String

    See if code below works for you:
    Imports System
    Imports System.Collections.Generic
    Imports System.Linq
    Imports System.Text
    Imports System.Collections
    Imports System.Data
    Imports System.Configuration
    Imports System.Data.OleDb
    
    Namespace Project
        Friend Interface bbank
            Sub [Select](ByVal query As String, ByVal tablename As String)
            Sub Insert(ByVal query As String)
            Sub Delete(ByVal query As String)
            Sub Update(ByVal query As String)
            Function cnfrm_username_password(ByVal name As String, ByVal password As String) As String
    
        End Interface
    
        Friend MustInherit Class bank
            Implements bbank
            Public conn As New OleDbConnection()
            Public dadapt As New OleDbDataAdapter()
            Public dset As New DataSet()
            Public MustOverride Sub [Select](ByVal query As String, ByVal tablename As String) Implements bbank.Select
            Public MustOverride Sub Insert(ByVal query As String) Implements bbank.Insert
            Public MustOverride Sub Delete(ByVal query As String) Implements bbank.Delete
            Public MustOverride Sub Update(ByVal query As String) Implements bbank.Update
            Public MustOverride Function cnfrm_username_password(ByVal name As String, ByVal password As String) As String Implements bbank.cnfrm_username_password
            Public Shared username As String
            Public Shared password As String
        End Class
    
        Friend Class Parent
            Inherits bank
    
            Public Sub New()
                conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Database.mdb"
                conn.ConnectionString = ""
    
                conn.Open()
            End Sub
    
            Public Overrides Sub [Select](ByVal query As String, ByVal tablename As String)
                dadapt = New OleDbDataAdapter(query, conn)
                dadapt.Fill(dset, tablename)
            End Sub
    
            Public Overrides Sub Insert(ByVal query As String)
                Dim comd As New OleDbCommand(query, conn)
                comd.ExecuteNonQuery()
            End Sub
    
            Public Overrides Sub Delete(ByVal query As String)
                Dim comd As New OleDbCommand(query, conn)
                comd.ExecuteNonQuery()
            End Sub
    
            Public Overrides Sub Update(ByVal query As String)
                Dim comd As New OleDbCommand(query, conn)
                comd.ExecuteNonQuery()
            End Sub
    
    
            Public Overrides Function cnfrm_username_password(ByVal name As String, ByVal password As String) As String
                For Each row As DataRow In dset.Tables("Login").Rows
                    Dim n As String = row("User").ToString()
                    Dim p As String = row("Password").ToString()
                    If name = n AndAlso p = password Then
                        bank.username = n
                        bank.password = p
                        Return "match"
    
                    End If
    
                Next row
                Return "notmatch"
            End Function
        End Class
    End Namespace


    Paul ~~~~ Microsoft MVP (Visual Basic)

    • Proposed as answer by The Thinker Thursday, May 3, 2012 12:28 PM
    • Marked as answer by crs81 Thursday, May 3, 2012 12:40 PM
    Thursday, May 3, 2012 12:23 PM

All replies

  • You can use any of the free on-line converters for this task.  For instance:
    http://www.developerfusion.com/tools/convert/csharp-to-vb/
    Thursday, May 3, 2012 10:23 AM
  • Thanks for give correct answer,

    After converting I am getting an error

    Classes can inherit only from other classes.  in

    MustInherit Class bank
            Inherits bbank

    code. please do the needful , complete code are below.

    <code>

    Imports System.Collections.Generic
    Imports System.Linq
    Imports System.Text
    Imports System.Collections
    Imports System.Data
    Imports System.Configuration
    Imports System.Data.OleDb

    Namespace project
        Interface bbank
            Sub [Select](query As String, tablename As String)
            Sub Insert(query As String)
            Sub Delete(query As String)
            Sub Update(query As String)
            Function cnfrm_username_password(name As String, password As String) As String

        End Interface

        MustInherit Class bank
            Inherits bbank
            Public conn As New OleDbConnection()
            Public dadapt As New OleDbDataAdapter()
            Public dset As New DataSet()
            Public MustOverride Sub [Select](query As String, tablename As String)
            Public MustOverride Sub Insert(query As String)
            Public MustOverride Sub Delete(query As String)
            Public MustOverride Sub Update(query As String)
            Public MustOverride Function cnfrm_username_password(name As String, password As String) As String
            Public Shared username As String
            Public Shared password As String
        End Class

        Class Parent
            Inherits bank

            Public Sub New()
                conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Database.mdb"
                conn.ConnectionString = ""

                conn.Open()
            End Sub

            Public Overrides Sub [Select](query As String, tablename As String)
                dadapt = New OleDbDataAdapter(query, conn)
                dadapt.Fill(dset, tablename)
            End Sub

            Public Overrides Sub Insert(query As String)
                Dim comd As New OleDbCommand(query, conn)
                comd.ExecuteNonQuery()
            End Sub

            Public Overrides Sub Delete(query As String)
                Dim comd As New OleDbCommand(query, conn)
                comd.ExecuteNonQuery()
            End Sub

            Public Overrides Sub Update(query As String)
                Dim comd As New OleDbCommand(query, conn)
                comd.ExecuteNonQuery()
            End Sub


            Public Overrides Function cnfrm_username_password(name As String, password As String) As String
                For Each row As DataRow In dset.Tables("Login").Rows
                    Dim n As String = row("User").ToString()
                    Dim p As String = row("Password").ToString()
                    If name = n AndAlso p = password Then
                        bank.username = n
                        bank.password = p

                        Return "match"

                    End If
                Next
                Return "notmatch"
            End Function
        End Class
    End Namespace

    </code>

    Thursday, May 3, 2012 11:34 AM
  • Rather than blindly using the code converter (which often have trouble converting things), look at your code.

    What is bbank?

    Is it a class, or something else?

    Do you inherit a class or implement a class? (Lookup implements and Inherits).

    What is an Interface?

    How do you Implement an interface?


    Stephen J Whiteley

    Thursday, May 3, 2012 11:50 AM
    Moderator
  • Yes this is a project.cs file

    Thursday, May 3, 2012 11:56 AM
  • I see one line that is incorrect:

    Public MustOverride Function cnfrm_username_password(name As String, password As String) As String

    See if code below works for you:
    Imports System
    Imports System.Collections.Generic
    Imports System.Linq
    Imports System.Text
    Imports System.Collections
    Imports System.Data
    Imports System.Configuration
    Imports System.Data.OleDb
    
    Namespace Project
        Friend Interface bbank
            Sub [Select](ByVal query As String, ByVal tablename As String)
            Sub Insert(ByVal query As String)
            Sub Delete(ByVal query As String)
            Sub Update(ByVal query As String)
            Function cnfrm_username_password(ByVal name As String, ByVal password As String) As String
    
        End Interface
    
        Friend MustInherit Class bank
            Implements bbank
            Public conn As New OleDbConnection()
            Public dadapt As New OleDbDataAdapter()
            Public dset As New DataSet()
            Public MustOverride Sub [Select](ByVal query As String, ByVal tablename As String) Implements bbank.Select
            Public MustOverride Sub Insert(ByVal query As String) Implements bbank.Insert
            Public MustOverride Sub Delete(ByVal query As String) Implements bbank.Delete
            Public MustOverride Sub Update(ByVal query As String) Implements bbank.Update
            Public MustOverride Function cnfrm_username_password(ByVal name As String, ByVal password As String) As String Implements bbank.cnfrm_username_password
            Public Shared username As String
            Public Shared password As String
        End Class
    
        Friend Class Parent
            Inherits bank
    
            Public Sub New()
                conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Database.mdb"
                conn.ConnectionString = ""
    
                conn.Open()
            End Sub
    
            Public Overrides Sub [Select](ByVal query As String, ByVal tablename As String)
                dadapt = New OleDbDataAdapter(query, conn)
                dadapt.Fill(dset, tablename)
            End Sub
    
            Public Overrides Sub Insert(ByVal query As String)
                Dim comd As New OleDbCommand(query, conn)
                comd.ExecuteNonQuery()
            End Sub
    
            Public Overrides Sub Delete(ByVal query As String)
                Dim comd As New OleDbCommand(query, conn)
                comd.ExecuteNonQuery()
            End Sub
    
            Public Overrides Sub Update(ByVal query As String)
                Dim comd As New OleDbCommand(query, conn)
                comd.ExecuteNonQuery()
            End Sub
    
    
            Public Overrides Function cnfrm_username_password(ByVal name As String, ByVal password As String) As String
                For Each row As DataRow In dset.Tables("Login").Rows
                    Dim n As String = row("User").ToString()
                    Dim p As String = row("Password").ToString()
                    If name = n AndAlso p = password Then
                        bank.username = n
                        bank.password = p
                        Return "match"
    
                    End If
    
                Next row
                Return "notmatch"
            End Function
        End Class
    End Namespace


    Paul ~~~~ Microsoft MVP (Visual Basic)

    • Proposed as answer by The Thinker Thursday, May 3, 2012 12:28 PM
    • Marked as answer by crs81 Thursday, May 3, 2012 12:40 PM
    Thursday, May 3, 2012 12:23 PM
  • Nice paul It looks like he was trying to copy a bank helper source code sample from some website but the really nice banking applications/class helpers are probably bought or written from scratch.

    Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering - Yoda. Blog - http://jefferycarlsonblog.blogspot.com/


    Thursday, May 3, 2012 12:29 PM
  • Thanks a lot, It is working now
    Thursday, May 3, 2012 12:30 PM