Click here to Skip to main content
15,906,645 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: Calling Dll C++ functions from Visual Basic 6 Pin
Dave Kreskowiak19-Apr-07 3:37
mveDave Kreskowiak19-Apr-07 3:37 
GeneralRe: Calling Dll C++ functions from Visual Basic 6 Pin
Kiske19-Apr-07 3:54
Kiske19-Apr-07 3:54 
GeneralRe: Calling Dll C++ functions from Visual Basic 6 Pin
Dave Kreskowiak19-Apr-07 4:41
mveDave Kreskowiak19-Apr-07 4:41 
QuestionGraphics in VB Pin
Kumaran21cen19-Apr-07 2:46
Kumaran21cen19-Apr-07 2:46 
AnswerRe: Graphics in VB Pin
Dave Kreskowiak19-Apr-07 4:43
mveDave Kreskowiak19-Apr-07 4:43 
Questionstill cant do it(add to database) Pin
peteyshrew19-Apr-07 2:22
peteyshrew19-Apr-07 2:22 
AnswerRe: still cant do it(add to database) Pin
peteyshrew19-Apr-07 2:32
peteyshrew19-Apr-07 2:32 
GeneralRe: still cant do it(add to database) Pin
Dave Kreskowiak19-Apr-07 3:31
mveDave Kreskowiak19-Apr-07 3:31 
peteyshrew wrote:
it was something so simple its stupid.


That happens alot in this business, even to the Pro's! :->

I noticed you're using the same connection string and just retyping it over and over when you need it, at least twice anyway. You might want to consider moving your database code to a seperate layer, or at least moving the connection code to a Shared (static in C#) method, like this:
Public Class SqlHelpers
    Public Shared GetConnection(ByVal OleDbFileName As String) As OleDbConnection
        ' Your connection string goes here.  Whether it's hard coded (bad idea!), or
        ' stored in the registry or in an app.config file, this method should
        ' retrieve it and create a new connection object out of it.
        '
        ' This example will see if the specified database exists in the same path
        ' the .EXE was launched from, and if so, create a new OleDbConnection out of it.
        Dim FullPath As String = Path.Combine(Application.StartupPath, OleDbFileName)
        If File.Exists(FullPath) Then
            Dim connString As String = String.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}", FullPath)
            Return New OleDbConnection(connString)
        Else
            Throw New FileNotFoundException("Unable to find the database file " & _
                OleDbFileName & " in the application startup path!")
        End If
    End Sub

    .
    . other helper methods...
    .
End Class

When you want to get a new connection to the database, just do this:
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
    Try
        Dim conn As OleDbConnection = SqlHelpers.GetConnection("PCBank.mdb")
        Dim comm As New OleDbCommand("insert into customers CustomerID, CustomerSurname, CustomerForename) " & _
            "values('" & (tbID.Text) & "','" & (tbSur.Text) & "','" & (tbFor.Text) & "')", conn)
        icount = comm.ExecuteNonQuery()
        MsgBox("record inserted")
    Catch ex As Exception
        MsgBox(ex.Message)
    Finally
        If Not IsNothing(conn) AndAlso conn.State <> ConnectionState.Closed Then
            conn.Close()
        End If
    End Try
End Sub

This is nowhere near the "perfect" implementation, but it gives you an idea of what should be going on.


Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic
     2006, 2007


GeneralRe: still cant do it(add to database) Pin
Psycho-*Coder*-Extreme22-Apr-07 8:36
Psycho-*Coder*-Extreme22-Apr-07 8:36 
AnswerRe: still cant do it(add to database) Pin
klaydze19-Apr-07 3:19
klaydze19-Apr-07 3:19 
QuestionASP.NET Connection with sql server 2005. Pin
Sujit Mandal19-Apr-07 2:02
Sujit Mandal19-Apr-07 2:02 
AnswerRe: ASP.NET Connection with sql server 2005. Pin
kubben19-Apr-07 2:05
kubben19-Apr-07 2:05 
GeneralRe: ASP.NET Connection with sql server 2005. Pin
Sujit Mandal19-Apr-07 2:16
Sujit Mandal19-Apr-07 2:16 
GeneralRe: ASP.NET Connection with sql server 2005. Pin
kubben19-Apr-07 2:18
kubben19-Apr-07 2:18 
GeneralRe: ASP.NET Connection with sql server 2005. Pin
Sujit Mandal19-Apr-07 2:24
Sujit Mandal19-Apr-07 2:24 
GeneralRe: ASP.NET Connection with sql server 2005. Pin
kubben19-Apr-07 2:31
kubben19-Apr-07 2:31 
GeneralRe: ASP.NET Connection with sql server 2005. Pin
Sujit Mandal19-Apr-07 2:42
Sujit Mandal19-Apr-07 2:42 
GeneralRe: ASP.NET Connection with sql server 2005. Pin
Sujit Mandal19-Apr-07 2:54
Sujit Mandal19-Apr-07 2:54 
Questionhow to get infiniti symbol by using ASCII code? what is the number? Pin
merlynml18-Apr-07 22:37
merlynml18-Apr-07 22:37 
AnswerRe: how to get infiniti symbol by using ASCII code? what is the number? Pin
Steven J Jowett19-Apr-07 0:20
Steven J Jowett19-Apr-07 0:20 
GeneralRe: how to get infiniti symbol by using ASCII code? what is the number? Pin
merlynml19-Apr-07 0:35
merlynml19-Apr-07 0:35 
GeneralRe: how to get infiniti symbol by using ASCII code? what is the number? Pin
Dave Kreskowiak19-Apr-07 1:47
mveDave Kreskowiak19-Apr-07 1:47 
GeneralRe: how to get infiniti symbol by using ASCII code? what is the number? Pin
merlynml19-Apr-07 2:06
merlynml19-Apr-07 2:06 
QuestionCREATING DATABASE USING SQLSERVER 2005 EXPRESS Pin
klaydze18-Apr-07 22:14
klaydze18-Apr-07 22:14 
AnswerRe: CREATING DATABASE USING SQLSERVER 2005 EXPRESS Pin
Steven J Jowett19-Apr-07 0:17
Steven J Jowett19-Apr-07 0:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.