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
Solved

Connection String in VB 2008

Posted on 2011-09-17
16
287 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Modal Popup Extender control 1 38
Sending receiving text messages in vb.net 15 48
Optimize the query 5 43
vb.net convert long time to mm:ss 23 12
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

856 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