Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

.Net Code Will Not Work

  • 23-04-2007 10:27am
    #1
    Closed Accounts Posts: 110 ✭✭


    Hey
    I am currently having problems in gettting certain VB programs to work.
    I cannot get the program to print stuff and also I cannot get the programs to work with databases

    When I put this code into my program:
    Dim dbMyDB As Database
    Dim rsMyRS As RecordSet

    Private Sub Form_Load()

    Set dbMyDB = OpenDatabase("MyDatabase.mdb")
    Set rsMyRS = dbMyDB.OpenRecordSet("MyTable", dbOpenDynaset)

    If Not rsMyRS.EOF Then rsMyRS.MoveFirst
    Do While Not rsMyRS.EOF
    lstRecords.AddItem rsMyRS!Name
    lstRecords.ItemData(lstRecords.NewIndex) = rsMyRS!ID
    rsMyRS.MoveNext
    Loop

    End Sub


    It gives me this error:

    Type 'DataBase' is not defined

    I do not have Microsoft Access on the computer that i am working on although i do have the database saved on the computer and i dont really think that, that should cause a problem anyway.

    The version of visual basic i am using is the free express edition from microsoft. could this be the reason why nothing seems to work or is it just good old stupidity on my part???


Comments

  • Registered Users, Registered Users 2 Posts: 500 ✭✭✭warrenaldo


    well for printing stuff - i dont know - i use msgbox("HELLO") as my print method. itll give you a popup box - if its just for debuggin that you want to print. its handy.

    with the db. i have written a dbconnect class which i can access from my entire program. its in the appcode folder so ive global access to it. here it is - very simple.

    Imports Microsoft.VisualBasic

    Public Class dbConnect

    Public s As String = System.Configuration.ConfigurationManager.ConnectionStrings("TestingDatabaseConnectionString").ConnectionString
    Public c As New System.Data.SqlClient.SqlConnection(s)
    Public cmd As New System.Data.SqlClient.SqlCommand("", c)

    Public Sub openConnection()
    c.Open()
    End Sub
    Public Sub closeConnection()
    c.Close()
    End Sub
    End Class

    Now i am using SQL Server - but may pointnu in the right direction. Hope it helps.


  • Registered Users, Registered Users 2 Posts: 1,345 ✭✭✭Squall


    That error basically means VB doesnt know what the Database object your declaring is.

    Have you got a Database class that your referencing? If not then thats most likely your problem.


  • Registered Users, Registered Users 2 Posts: 2,426 ✭✭✭ressem


    Your code is based on examples of old Visual Basic 6 code.

    Visual Basic .Net is a whole different beastie, hardly the same language.

    Try looking at http://www.startvbdotnet.com/ado/msaccess.aspx
    and note the references to oledb.

    In the same way, writing stuff to the screen uses
    System.Console.WriteLine("text here");


  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    Your code looks like it was ported from Access (VBA) rather than VB6.

    There are plenty of examples out there on how to use VB.NET as ressem pointed out. There is an upgrade advisor tool for this sort of stuff but I would recommend that you dont use it becase it will cause a few issues and unless you are familiar with it, it can make your life hard!


Advertisement