ADO.NET常识汇总

ADO.NET知识汇总

这又是一篇记录平常工作笔记的博客,无论是在排版还是解说上都不会有太多要求。同时这也是一篇不上博客园首页的博客,Just记录一些工作笔记。

vSelect返回单个值

            string connSQL = @"Data Source=SQLAVSDCL5001PX; Initial Catalog=AVSubmit; Integrated Security=SSPI";
            using (SqlConnection conn = new SqlConnection(connSQL))
            {
                string strSQL = "select count(*) from [dbo].[DeterminationType]";
                SqlCommand cmd = new SqlCommand(strSQL, conn);//创建Command对象 

                try
                {
                    conn.Open();//一定要注意打开连接 
                    int rows = (int)cmd.ExecuteScalar();//执行命令 
                    Console.WriteLine("执行ExcuteScalar方法:共{0}行记录", rows);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("\nError:\n{0}", ex.Message);
                }
            }

            Console.Read();