使用C#的SQL Server Compact 3.5数据库操作 [英] SQL Server Compact 3.5 Database manipulation using C#

查看:91
本文介绍了使用C#的SQL Server Compact 3.5数据库操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请问有人告诉我这段代码有什么问题吗?

Pls can someone tell me whats wrong with this code?

openConnection();
            SqlCeCommand cmd = new SqlCeCommand("SELECT main_password, default_password FROM password WHERE id = 1", con);
            try
            {
                SqlCeDataReader r = cmd.ExecuteReader();
                if (r.Read())
                {
                    passwordtxt = (string) r.Rows[0]["main_password"];
                }
                if (string.IsNullOrEmpty(passwordtxt))
                {
                    passwordtxt = (string) r.Rows[0]["default_password"];
                }
            }
            catch(SqlCeException sqlException)
            {
                MessageBox.Show(sqlException.Message,"Problem1",MessageBoxButtons.OK,MessageBoxIcon.Information);
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message,"Problem2",MessageBoxButtons.OK,MessageBoxIcon.Information);
            }
            finally
            {
                con.Close();
                cmd.Dispose();
                con.Dispose();
            }

推荐答案

使用DataReader的方式不正确.

在此处阅读有关ADO.NET的信息,它将对您有所帮助.

看看这些:
使用DataReader(ADO.NET)检索数据 [ ^ ]
DataReader类 [
The way you use DataReader is not correct.

Read about ADO.NET here and it will help you.

Look at these:
Retrieving Data Using a DataReader (ADO.NET)[^]
DataReader Class[^]


这篇关于使用C#的SQL Server Compact 3.5数据库操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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