http://user.qzone.qq.com/810087456/infocenter

ymecho

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
            SqlConnection con = new SqlConnection();          
            string s = System.Environment.CurrentDirectory; //exe 所在路径
            int i = 0;
            while (i < 0)
            {
                i++;
                int add = s.LastIndexOf(@"\");
                s = s.Substring(0, add);
            }
            s += "\\ERP_IIP.mdf";
            try
            {
                con.ConnectionString = "Data Source=.\\;AttachDbFilename=" + s + ";Integrated Security=True;User Instance=false";
                con.Open();

                DataSet ds = new DataSet();
                string SQLString = "SELECT     TOP (2) ID, USERID, PWD, WORKERCODE, USERNAME, ROLEID, ISEFFECT, WSHCODE, Sex FROM         TB_USER ORDER BY NEWID()";
                SqlDataAdapter command = new SqlDataAdapter(SQLString, con);
                command.Fill(ds, "ds");
                con.Close();
                Program.name = ds.Tables[0].Rows[0]["USERNAME"].ToString();
            }
            catch
            {
                Program.name = "无数据源!";
            }
            label1.Text = Program.name;

直接连接*.mdf 文件,去除随机两条记录。

posted on 2013-04-18 22:27  ymecho  阅读(222)  评论(1编辑  收藏  举报