I Create a Ms sql server database called MyDBs and try to made it as movable, attachement database by do this way in Microsoft SQL Server Management:
Script database as - CREATE TO - File
I took the file Of DataBase(MyDBs) and put it in Debug folder in my project.
and try this code to load the data from database:
and it showed me this error: The type initializer for 'OOP__CreatProject.Module4' threw an exception.
Imports System.Data.SqlClient
vb Code:
Module Module4 Dim MyConnection As SqlConnection = New SqlConnection("Provider=SQLOLEDB.1; " & "Data Source=" & Application.StartupPath & "\MyDBs.sql") Public Sub Load_DBmsqldata() Dim sql As String = " Select Name,Tel,Addr from Table1 " Dim dp As New SqlDataAdapter(sql, MyConnection) Dim Table1 As New DataTable dp.Fill(Table1) Form1.DataGridView1.DataSource = Table1 End Sub End Module




Reply With Quote