查询

控制层

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using System.Data;
using System.Data.SqlClient;


namespace MvcApplication5.Controllers
{

     
    public class TestController : Controller
    {
        //
        // GET: /Test/
    
        public ActionResult Index()
        {
       
            SqlConnection conn = new SqlConnection("server=.;database=AAA;Integrated Security=True");
            conn.Open();
            SqlCommand data = new SqlCommand("select COUNT(*) ABC from haha ", conn);
            //var mc =data.ExecuteReader();
            SqlDataReader dr = data.ExecuteReader();
            while (dr.Read()) //读取信息
            {
                ViewData["Message"] = dr["ABC"].ToString();

            }
          
            conn.Close();
            return View();
            
            
        }

    }
}

 

显示层

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

  <%:ViewData["Message"] %>

</asp:Content>

 

  

posted @ 2015-03-13 18:59  fleam  阅读(160)  评论(0编辑  收藏  举报