简体   繁体   English

检索存储在Visual Studio 2010中的SQL Server CE数据库中的信息

[英]Retrieving information stored in a SQL Server CE database in Visual Studio 2010

I asked a question [HERE] and we got all the information stored in the database SQL Server CE database. 我问了一个问题[HERE] ,我们将所有信息存储在SQL Server CE数据库中。

The question remains now how to get the information stored back into variables. 现在的问题仍然是如何将信息存储回到变量中。

This line of code: 这行代码:

myReader.SqlCeReader();

will not compile, I am asked if I have missed a compiler reference what ever that is. 不会编译,我被问到是否错过了编译器参考。

The information is stored as strings with an Integer “ID” primary key. 信息以带有整数“ ID”主键的字符串存储。

The information will be used to create shortcuts on a disk suitable for launching, images in paint, executable programs and so on. 该信息将用于在适合启动的磁盘上创建快捷方式,绘画中的图像,可执行程序等。 They should not be more than strings which is why I find it hard to do, it should be simple. 它们不应该只是字符串,这就是为什么我觉得很难做到的原因,它应该很简单。

A sample record 样本记录

id=int NstacksName=String NstacksPath=String.

I think I have it all wrong and am surprised it even compiles this far. 我认为我全都错了,很惊讶它到目前为止还可以编译。

private void label2_Click(object sender, EventArgs e)
{
    string DirName;

    SqlCeConnection conn = new SqlCeConnection("Data Source=C:\\Users\\username\\Documents\\Visual Studio 2010\\Projects\\NStacks1\\NStacks1\\Database1.sdf");

    String name;

    try
    {
        conn.Open();

        SqlCeCommand Command = new SqlCeCommand("SELECT * FROM NStacks1 WHERE ID = 1", conn);

        DataTable Data = new DataTable();
        SqlCeDataAdapter adapter = new SqlCeDataAdapter(Command);

        SqlCeDataReader myReader;

        try
        {
             myReader.SqlCeReader();

             DirName = Data.ToString();
             con.Close();
             name = DirName;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         con.Close();
     }
}
    private void button4_Click(object sender, EventArgs e)
    {
        string SName, NStackPath;

        string source=("Data Source=C:\\Users\\username\\Documents\\Visual Studio 2010\\Projects\\NStacks1\\NStacks1\\Database1.sdf");
        SqlCeConnection Con = new SqlCeConnection(source);
        try{
            Con.Open();
            string Query= "SELECT * FROM Nstacks1 WHERE ID=1";
            SqlCeCommand command = new SqlCeCommand(Query , Con);
            SqlCeDataReader dr = command.ExecuteReader();
            if (dr.Read())
            { 
                textBox1.Text=(dr["NStacksName"].ToString());
                label2.Text = (dr["NStacksItem"].ToString());

            }
            Con.Close();
           }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                con.Close();
            }
       }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SQL Server 2005,Visual Studio 2010和存储过程 - SQL server 2005, Visual Studio 2010 and stored procedures 将数据库SQL Server 2008链接到Visual Studio 2010 - Linked database sql server 2008 to visual studio 2010 如何使用SQL Server CE和C#更新dB表中的单元格值(Visual Studio 2010) - How can I update a cell value in a dB table, using SQL Server CE and C# (Visual Studio 2010) 解析查询SQL Server CE / VS 2010本地数据库时出错 - There was an error parsing the query SQL Server CE / VS 2010 local database 使用Visual Studio 2010连接到SQL Server Express - Connection to sql server express with visual studio 2010 在Visual Studio 2010中自动生成SQL存储的翻译生成 - Automate sql stored translation generation in Visual Studio 2010 在Visual Studio中管理SQL Server存储过程 - Manage SQL Server stored procedures in Visual Studio 在Visual Studio中使用SQL Server存储过程 - Using a SQL Server Stored Procedure in Visual Studio 如何在Visual Studio-2010中的运行时刷新SQL Server数据库表? - How to refresh SQL Server database table during runtime in Visual Studio-2010? 如何将SQL Server 2008 R2数据库添加到Visual Studio 2010安装文件中? - How to add my SQL Server 2008 R2 database to my Visual Studio 2010 Setup File?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM