本文介绍了[问]如何将SDF数据库显示到datagridview?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试学习如何通过代码将sdf数据库从sql server compact填充到datagridview中。在sql server(mdf数据库)应该是这样的
I try to learn how to populate sdf database from sql server compact into datagridview through codes. In sql server (mdf database) should look like this
Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
Dim cn As SqlConnection
Private Sub MyConnection()
Try
Dim cnSQL As String = "Server=MyServer;Database=Database1;Trusted_Connection=true"
Me.cn = New SqlConnection(cnSQL)
cn.Open()
cn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Me.MyConnection()
Dim dtSet As DataSet = New DataSet
Dim dtAdapter As SqlDataAdapter = New SqlDataAdapter("Select * from TableDatabase1", cn)
dtAdapter.Fill(dtSet)
Me.DataGridView1.DataSource = dtSet.Tables(0)
End Sub
End Class
但是,该代码对SDF数据库不起作用。我正在使用VB 2010和Default VS 2010 SQL Server。那么,我应该为SDF dabase编写什么代码?我只想要代码。在此先感谢。
However, that code doesn''t work for SDF database. I''m using VB 2010 and Default VS 2010 SQL Server. So, what code should I write for SDF dabase? I want in code only. Thanks in advance.
推荐答案
Dim cnSQL As String = "Data Source=C:\SomeFolder\DataFileName.sdf;Persist Security Info=False"
这篇关于[问]如何将SDF数据库显示到datagridview?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!