[问]如何将SDF数据库显示到datagridview? [英] [ASK] How to display SDF database to datagridview?

查看:61
本文介绍了[问]如何将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.

推荐答案

使用SDF,您可能意味着SQL Server CE数据库文件。如果这是正确的,那么我猜你的连接字符串有问题。



SQL Server CE没有像Express这样的数据库引擎版有。因此,CE数据库通过直接连接到文件来使用。



您的连接字符串应如下所示:

With SDF you probably mean a SQL Server CE database file. If that''s correct, then I guess you have a problem with your connection string.

SQL Server CE doesn''t have a database engine like for example Express edition has. Because of this, CE databases are used by connecting directly to the file.

Your connection string should look something like:
Dim cnSQL As String = "Data Source=C:\SomeFolder\DataFileName.sdf;Persist Security Info=False"


我看到你正在使用sdf文件编程。

你知道.sdf文件吗?它用于数据库。我打算做一个sdf查看器,但我不知道从哪里开始。你能帮助我吗?

我需要使用vb.net制作一个sdf查看器应用程序(基于窗口)
i see that you''re programming using sdf files.
do you know about .sdf files? its use for databases. i am going to make a sdf viewer but i dont know where to start. can you help me?
i need to make a sdf viewer application using vb.net (window-based)


这篇关于[问]如何将SDF数据库显示到datagridview?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆