• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 295
  • Last Modified:

Connection String in VB 2008

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
mustish1
Asked:
mustish1
2 Solutions
 
Jacques Bourgeois (James Burger)PresidentCommented:
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
 
mustish1Author Commented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
SAMIR BHOGAYTAFreelancer and IT ConsultantCommented:
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
 
Jacques Bourgeois (James Burger)PresidentCommented:
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
 
mustish1Author Commented:
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
 
mustish1Author Commented:
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
 
mustish1Author Commented:
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
 
Jacques Bourgeois (James Burger)PresidentCommented:
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
 
mustish1Author Commented:

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
 
mustish1Author Commented:
I am using Access 2010
0
 
Jacques Bourgeois (James Burger)PresidentCommented:
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
 
mustish1Author Commented:
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
 
Jacques Bourgeois (James Burger)PresidentCommented:
When does it says that? On which line?
0
 
mustish1Author Commented:
   Dim myConn As OleDbConnection = New OleDbConnection();
0
 
Jacques Bourgeois (James Burger)PresidentCommented:
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now