Creating a basic database

databases , db Delhi, India
  • 13 years ago

     Hi

    I'm new here and really just starting out on database programming using VB6 and express. Previously I've used Delphi so I'm experiencing transition pains. Here goes anyway!

    I've successfully created a basic program connecting to an Access database which allows me to navigate, delete, create records etc. So far so good.  (I think it's ADO not DAO but how do I know!!!) Here's the relevant connections.

    con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\databases\AddressBook.mdb"

    Dim con As New OleDb.OleDbConnection
        Dim dst As New DataSet
        Dim da As OleDb.OleDbDataAdapter
       da = New OleDb.OleDbDataAdapter(Sql, con)

    Everything works OK with one form. I want to have a new form to do some searches of the table(s) but when I copy over the successful form1 code I get:

    NullReferenceException was unhandled 

    Any advice please about the problem and the best way to set up a connection to a database so I can use that connection through a whole application.

    Many thanks in anticipation.

    Rod 

  • 13 years ago

    The way i do it is like this.

     Dim cn1 as New adodb.connection    ' create a new connection thingi

    cn1.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\DJ Spares\Details.mdb;Persist Security Info=False"   ' opens the connection

    Then if you want to read records i define a recordset

    Dim rs1 as new adodb.recordset

     The rs1.open "SELECT * FROM details",cn1

    you want to execute then

    cn1.execute "INSERT INTO details(address)" & "VALUES('" & text1.text & "')"

     I think your problem is handlin the nulls.in access it will give you an error if a field you are readin is empty. Make sure that nothin is null.

    Best of luck.

     

    Elabuwa

    If you want i'll attach you some sourcecode. let me know

  • 13 years ago

     Hi

    I'm new here and a beginner in programming database using vb 6, can you teach me or can you send me a sample code in making a database

    thanks!!  

  • 13 years ago

    Hi royo, da,

     

    I have uploiaded a simple tutorial i created in vb6. this is the link.

    http://www.megaupload.com/?d=X99FQB6W.

    You need to have the .mdb file in C:/ directory.

    and thats all you need.

    play around with the adodc1 properties as well. that will let you create a connection string easily which you will need to tell vb6 to connect to the appropriate database.

    If you need anymore help lemme kno. Once you have mastered inserting records and selecting records i will teach you to update records

     

    Elabuwa

     

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“A computer lets you make more mistakes faster than any other invention in human history, with the possible exceptions of handguns and tequila” - Mitch Ratcliffe