ifendo

访问本地Access 数据出错

访问本地的access数据库时,出现了OleDbException

 

 

10Aug2015 晚:

 

好像找到了问题所在, 虽然不知道背后深层次的原因

改用了C#, 然后command 语句里也update了下,

具体是这样的

        private void button2_Click(object sender, EventArgs e)
        {
            //connection
            OleDbConnection conn = new OleDbConnection();
            String constr;

            constr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\BegASPNET\DataLabs.mdb";
            conn.ConnectionString = constr;
            //command
            OleDbCommand cmd = new OleDbCommand();
            String cmdtext;
            cmdtext = "select count(*) from [Domain]";
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = cmdtext;

            //execute
            // Dim ds As SqlDataReader()
            conn.Open();

            //MessageBox.Show();

            if (conn.State == ConnectionState.Closed)
            {
                MessageBox.Show("wrong");
            }
            else
            {
                MessageBox.Show("opened");
            }
           
            //OleDbDataReader dr;
            //dr= cmd.ExecuteReader();
            //MessageBox.Show(dr.GetString(0));
            String n;
            n = cmd.ExecuteScalar().ToString();
            MessageBox.Show(" We have " + n + " Domains in total\n" + "Love you, HHM");

            conn.Close();
        }

 

后来就成功了,有点小高兴,总算有点进展了

 

posted on 2015-08-06 09:27  ifendo  阅读(...)  评论(...编辑  收藏

My Links

Blog Stats