Connection String
Connection String
Professional and have installed that. I downloaded the Northwind template from Microsoft's Website and created a database with it (I guess that's what I did, anyway) named Northwind 2007.accdb. When I try to do the Try It Out involving the DataGridView Control in Chapter 3 at step 9, I get an error message that the file is not in a recognized format. Is there an add-on or something that will allow VB2005 to link to .accdb files, should I download the 2003 version of Northwind, can I convert the .accdb file to an .mdb? Thank you very much for your assistance. Eric
UPDATE: I went searching on MSDN and found the answer to my question. Here are step-by-step instructions as displayed in the forum post at http://forums.microsoft.com/MSDN/Sho...94617&SiteID=1 Step by step instructions. From the Add Connection dialog:
1) Click the Change button for the Data Source 2) From the Change Data Source dialog select <other> in the Data source list 3) Click the OK button 4) Back to the Add Connection dialog select Microsoft Offfice 12.0 Access Database Engine OLE DB Provider from the OLE DB Provider drop down 5) In the Server or file name text box enter the path to your Access 2007 database file 6) Click the Test Connection button to make certain that you can connect to the database 7) Click on the OK button to finish creating the data source.
Below is the text. The new office suite version 2007 comes with brand-new file formats. One of them is the new Access database format version 2007 with accdb extension. Of course there is a new connection string for those new access databases. You can use the connection string below to access your accdb databases through asp.net. Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\database1.accdb;Persist Security Info=False; In addition, if you are using passwords to access your database, you can include it in your connection string like below; Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\database1.accdb;Jet OLEDB:Database Password=MyDbPassword; However, your hosting provider will not be aware of this upgrade or probably you don't want to install Access 2007 on your server. Actually, you don't need to. Just install 2007 Office System Driver: Data Connectivity Components.. Hope this helps.
Access is capable of handling multiple users, however once you get over 3 or 4 concurrent users you will start to notice that MS Access doesn't scale well. Access is designed for the professional but not an enterprise. Microsoft SQL Server (Express edition is free - upto 4GB space) is designed for a large number of concurrent users. I also want to limit the level of access of the users to the database in my program. You can use folder Permissions if you wish to restrict access to the file. Personally in my old VB6 apps that used MS Access I called the file db.resources rather than db.mdb. This is because a.resources file cant be downloaded if it is hosted online (ref DotNetNuke) and also so people dont know which program to open the file in. If you need role based security you need a enterprise level database such as SQL Server. I want to connect the program in all PCs to one database in another PC using Microsoft Access.
Here is how you can have two computers share the same database. a. Choose the main PC that will host the database b. Host the database in a folder that is shared to the other users c. Physically go over to the PC that isn't hosting the database, create a text fileon the desktop. d. Rename the file extension from .txt to .udl and press enter e. Double clcik the udl file and enter these settings and navigate to the shared folder that hosts the shared database:
f. Once the Test Connection is successful, close the Data Link Properties window. g. Right click the UDL file on the desktop and choose Open With and open with notepad h. You will see your connection string:
[oledb] ; Everything after this line is an OLE DB initstring Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\PCName\c$\temp\Database1.accdb;Persist Security Info=False i. Set the second pc to use the networked connection string.
Public Class Form1 Inherits System.Windows.Forms.Form Dim cn As OleDbConnection Dim cmd As OleDbCommand Dim dr As OleDbDataReader Private Sub Form1_Load(ByVal sender As System.Object, ByVal e as _ System.EventArgs) Handles MyBase.Load End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As_ System.EventArgs) Handles Button1.Click Try cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;_ Data Source=C:\emp.mdb;") 'provider to be used when working with access database cn.Open() cmd = New OleDbCommand("select * from table1", cn) dr = cmd.ExecuteReader While dr.Read() TextBox1.Text = dr(0) TextBox2.Text = dr(1) TextBox3.Text = dr(2) ' loading data into TextBoxes by column index End While Catch End Try dr.Close() cn.Close() End Sub End Class
1. dim mycon as new sqlConnection("your conn string") 2. dim myDataTable as new DataTable 3. myconn.open() 4. Dim myDataAdapter as new SqlDataAdapter("your query ", mycon) 5. myDataTable.table("MyTable").clear 6. MyDataAdapter.fill(myDataTable,"MyTable") 7. BindingSource1.datasource = myDataTable.table("MyTable") 8. GataGridView.DataSource = bindingsource1 9. EndSub
4. Dim dta As New Tb_AbsensiTableAdapter 5. Dim dttb As New DataTable 6. dttb = dta.GetData() 'the data table had data from dataset 7. DataGridView1.DataSource = dttb 'it doesn't work 8. 9. End Sub
1. Dim objdatatable As DataTable = objDataSet.Tables("TableName") 2. 3. With DataGridView1 4. .AutoGenerateColumns = True 5. .DataSource = objDataSet 6. .DataMember = "TableName" 7. 8. ' Declare and set the alternating rows style... 9. Dim objAlternatingCellStyle As New DataGridViewCellStyle() 10. objAlternatingCellStyle.BackColor = Color.WhiteSmoke 11. searchDataGridView.AlternatingRowsDefaultCellStyle = objAlternatingCellStyle 12.
Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim connectionString As String = "Data Source=.;Initial Catalog=pubs;Integrated Security=True" Dim sql As String = "SELECT * FROM Authors" Dim connection As New SqlConnection(connectionString) Dim dataadapter As New SqlDataAdapter(sql, connection) Dim ds As New DataSet() connection.Open() dataadapter.Fill(ds, "Authors_table") connection.Close() DataGridView1.DataSource = ds DataGridView1.DataMember = "Authors_table" End Sub End Class
Imports System.Data.OleDb Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="Your .mdb path";" Dim sql As String = "SELECT * FROM Authors" Dim connection As New OleDbConnection(connectionString) Dim dataadapter As New OleDbDataAdapter(sql, connection) Dim ds As New DataSet() connection.Open() dataadapter.Fill(ds, "Authors_table") connection.Close() DataGridView1.DataSource = ds DataGridView1.DataMember = "Authors_table" End Sub End Class
Public Class Form1 Dim con As ADODB.Connection Dim rs As ADODB.Recordset Dim tb As DataTable
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load con = New ADODB.Connection rs = New ADODB.Recordset tb = New DataTable con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\AMEER & SONS\AMEER&SONS.mdb;Persist Security Info=False" con.CursorLocation = ADODB.CursorLocationEnum.adUseClient con.Open() rs.Open("company_info", con, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic, 2) grid.DataSource = rs End Sub End Class
You havn't mapped any data to your DataTable, which you would use to fill the Grid:
SQL = "SELECT " & FieldList & " FROM tblMembers WHERE Status='Active'" DS = New DataSet Connection.Open() MyAdapter = New OleDbDataAdapter(SQL, Connection) MyAdapter.Fill(DS) Connection.Close() grid1.DataSource = DS.Tables(0)