SQL Server 精简版和 VB/C#

发布于 2024-12-12 19:21:39 字数 131 浏览 1 评论 0原文

谁能提供一个清晰简单的示例来说明如何打开 SSCE 数据库并使用 SELECT 语句对其进行查询?最终,我需要在一个我无法控制的系统上执行此操作,因此我使用的任何方法/提供程序都必须默认在标准 Windows 计算机上可用。

谢谢!

Can anyone provide a clear and simple example of how I can open a SSCE database and query it with a SELECT statement? Ultimately I'll need to do this on a system that I have no control over so whatever method/provider I use must be available by default on a standard Windows machine.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

春夜浅 2024-12-19 19:21:39

以下应该有效。您必须添加对 System.Data.SqlServerCe 的引用并为其创建一个 using 语句。

    string connectionString = "my connection string";
    string queryString = "select column from mytable where mycolumn = 'somevalue'";    
    using (var cnn = new SqlCeConnection(connectionString))
                        {
                            using (var cmd = new SqlCeCommand(queryString, cnn))
                            {
                                cnn.Open();

                                var da = new SqlCeDataAdapter(cmd);
                                var ds = new DataSet();
                                da.Fill(ds);

                            }
                        }

您还可以在调用 cnn.Open(); 后使用 cmd.Parameters.Add 向查询添加参数。

The following should work. you will have to add a reference to System.Data.SqlServerCe and create a using statement for it.

    string connectionString = "my connection string";
    string queryString = "select column from mytable where mycolumn = 'somevalue'";    
    using (var cnn = new SqlCeConnection(connectionString))
                        {
                            using (var cmd = new SqlCeCommand(queryString, cnn))
                            {
                                cnn.Open();

                                var da = new SqlCeDataAdapter(cmd);
                                var ds = new DataSet();
                                da.Fill(ds);

                            }
                        }

You can also use cmd.Parameters.Add after you call cnn.Open(); to add parameters to your query.

巷雨优美回忆 2024-12-19 19:21:39

对于遇到此问题的任何人,请查看这篇文章:

http://msdn.microsoft。 com/en-us/library/aa983326.aspx

那么就这么简单:

Imports System.Data.SqlServerCe

Public Class Form1

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    Try

        Using conn As New SqlCeConnection
            conn.ConnectionString = "Data Source=c:\Reporting.Database.sdf;Persist Security Info=False;"
            conn.Open()
            MsgBox("opened")
            conn.Close()
        End Using

    Catch ex As Exception
        MsgBox(ex.Message)

    End Try
End Sub
End Class

For anyone struggling with this, look at this article:

http://msdn.microsoft.com/en-us/library/aa983326.aspx

Then it's as simple as this:

Imports System.Data.SqlServerCe

Public Class Form1

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    Try

        Using conn As New SqlCeConnection
            conn.ConnectionString = "Data Source=c:\Reporting.Database.sdf;Persist Security Info=False;"
            conn.Open()
            MsgBox("opened")
            conn.Close()
        End Using

    Catch ex As Exception
        MsgBox(ex.Message)

    End Try
End Sub
End Class
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文