?
Solved

Connection String in VB 2008

Posted on 2011-09-17
16
Medium Priority
?
291 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 1000 total points
ID: 36555497
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 11

Assisted Solution

by:SAMIR BHOGAYTA
SAMIR BHOGAYTA earned 1000 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
 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

770 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