Solved

Connection String in VB 2008

Posted on 2011-09-17
16
284 Views
Last Modified: 2012-05-12
Hi guys: Can I use the same connection string which i use it in VB 2000 or in 98 in VB 2008 or its different in 2008 Thanks.

Dim rs2 As New Recordset
rs2.Open "stock", con, adOpenKeyset, adLockOptimistic, adCmdTable
0
Comment
Question by:mustish1
16 Comments
 
LVL 40
ID: 36555393
The code you show us is not a connection string.

But yes, you can still use the same connection strings.

However, the old ADO you were using has been replaces by a new thing called ADO.NET. You can still use the old ADO by referencing the ADODB library, but it you want to use technologies geared toward the future, technologies of 2011 instead of technologies from 15 years ago, you should learn to work with ADO.NET

Although the name is similar, although connections and commands are almost the same, the Recordset has been replaced by something called a DataTable, and its use is completely different. You will need to search around for a tutorial if you want to swith to 21st century technologies.
0
 

Author Comment

by:mustish1
ID: 36555405
Can you please send me the link how to use the new ado.net

Private Sub Command2_Click()
For i = Text1.LBound To Text1.UBound
    If Trim(Text1(i)) = "" Then
        MsgBox "Fields can't empty", vbInformation
        Text1(i).SetFocus
        Exit Sub
    End If
Next
'rs.Find "item_no='" & Trim(Text1(1)) & "'"
'If rs.RecordCount > 0 Then
    'MsgBox "Item already exist"
'Else
    rs!item_no = Trim(Text1(1))
    rs!Name = Trim(Text1(2))
    rs!qty = Val(Trim(Text1(3)))
    rs!Rate = Val(Trim(Text1(4)))
    rs!Value = Val(Trim(Text1(5)))
    rs.Update
'End If

'rs("item_no") = Text1
'rs("name") = text2
'rs("qty") = text3
'rs("rate") = text4
'rs("value") = text5

'DAO is old fashion and ADO is new fashion
'rs ! item_no
'exit for for the termination of for loop
'lbound(text1)
End Sub
0
 
LVL 15

Accepted Solution

by:
x77 earned 250 total points
ID: 36555497
0
 
LVL 11

Assisted Solution

by:SAMIR BHOGAYTA
SAMIR BHOGAYTA earned 250 total points
ID: 36556190
Hi,

You have to declare connection string in vb 2008 at web.config.

<add key="ConnectionString" value="Your ConnectionString">


Now you can access this into the whole application.
0
 
LVL 40
ID: 36556631
The comment about web.config is good only if you are developing a web application. web.config does not exist in a Windows application.

In a Windows application, you can use the connection string as you did before.

The link provided by x77 is a good start because it gives you an overal view of the concepts and techniques.
0
 

Author Comment

by:mustish1
ID: 36556977
I am trying to ask 2 inputs
Save and Cancel

I dont want this in main class. I try to create a sub procedure but it gives error.


Public Class Form1
    Dim YesNo As DialogResult
        YesNo = MessageBox.Show("Do you want to save Data?", _
        "Are you sure?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)
    Select Case YesNo

End Class

Private Sub Button1_Click()

End Sub
0
 

Author Comment

by:mustish1
ID: 36557260
ok. Its a class and its method. Still ive to figure it out how to add data on this button or cancel and stay in the form.


Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim YesNo As DialogResult
        YesNo = MessageBox.Show("Do you want to save this file?", _
        "Are you sure?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)
    Select YesNo
    End Sub
End Class
0
 

Author Comment

by:mustish1
ID: 36557359
Syntax error in connection string


Public Class Form1
    Dim myConn As OleDbConnection = New OleDbConnection()
myConn.ConnectionString=_
"Provider=Microsoft.Jet.OLEDB.4.0;Data " & _
"Source=C:\vbcl\My1.acdb;User ID=''; " &_
"Password=''"
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim YesNo As DialogResult
        YesNo = MessageBox.Show("Do you want to save this file?", _
        "Are you sure?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)
    Select YesNo
    End Sub
End Class
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 40
ID: 36557418
Do not break lines the way you do, with lots of concatenations. It makes it very hard to see the complete string and pinpoint problems.

There are errors in the connection string because you are using the UserID and Password parameters but do not give the information for either. If your database is not secured, do not provide those. Stop the string after acdb;
0
 

Author Comment

by:mustish1
ID: 36557436

Error      1      Type 'OleDbConnection' is not defined.      C:\Documents and Settings\Kathy\Local Settings\Application Data\Temporary Projects\WindowsApplication1\Form1.vb      2      19      WindowsApplication1

Public Class Form1
    Dim myConn As OleDbConnection = New OleDbConnection()
myConn.ConnectionString=_"Provider=Microsoft.Jet.OLEDB.4.0;Data " "Source=C:\vbcl\My1.acdb;
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim YesNo As DialogResult
        YesNo = MessageBox.Show("Do you want to save this file?", _
        "Are you sure?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)
        'Select YesNo
    End Sub
End Class

0
 

Author Comment

by:mustish1
ID: 36557439
I am using Access 2010
0
 
LVL 40
ID: 36557506
You've left an underline after ConnectionString=
You've got useless and damaging " " in Data " "Source
You've forgotten the " at the end of the ConnectionString
myConn.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\vbcl\My1.acdb;"

Open in new window

0
 

Author Comment

by:mustish1
ID: 36557576
It says OleDbConnection is not defined


Public Class Form1
    Dim myConn As OleDbConnection = New OleDbConnection();
    myConn.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\vbcl\My1.acdb;"
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim YesNo As DialogResult
        YesNo = MessageBox.Show("Do you want to save this file?", _
        "Are you sure?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)
        'Select YesNo
    End Sub
End Class
0
 
LVL 40
ID: 36557890
When does it says that? On which line?
0
 

Author Comment

by:mustish1
ID: 36557939
   Dim myConn As OleDbConnection = New OleDbConnection();
0
 
LVL 40
ID: 36558234
OleDbConnection is in the System.Data.OleDb namespace. Depending on how your environment is set up, you might have to specify the namespace (just as you usually have to define the path for a file.

Dim myConn As OleDbConnection = New System.Data.OleDb.OleDbConnection

Looks to me as you do not have the basics of .NET programming. I would not go for a database application for my first application. You will have too many things to deal with at the same time.

Learn the basics first. Learn the new syntax. VB.NET looks similar to the old VB, but it takes a while to grasp all those little changes that prevents things from working as they did.

I would suggest that you practice on a simpler application first. Once you will be at ease with the environment and the new stuff in Visual Studio and VB.NET, then try your hand at a database application.

The exercise I give my students is to design a calculator. Not too hard, but enough so that you have to break your old habits and start to understand the new ones.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now