当前位置:编程学习 > C#/ASP.NET >>

为什么我连接的数据库和我查询的表不一样却可以链接成功?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

namespace Test
{
    public partial class Demo : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                SqlConnection conn = new SqlConnection();
                conn.ConnectionString = "Data Source=.;Initial Catalog=CRM;Integrated Security=True";
                conn.Open();

                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = "select * from dept;";
                cmd.CommandType = CommandType.Text;
                cmd.Connection = conn;
                conn.Close();
                Response.Write("<script> alert('链接成功!') </script>");
            }
            catch
            {
                Response.Write("<script> alert('链接失败!') </script>");
            }
            
        }

        protected void BtnLogin_Click(object sender, EventArgs e)
        {
            
        }

    }
} --------------------编程问答-------------------- 什么意思?

select * from dept; 

后面多分号 --------------------编程问答--------------------  缓存问题,重启VS --------------------编程问答-------------------- What do you want to do? --------------------编程问答-------------------- 是不是真的哟。真奇怪。 --------------------编程问答-------------------- 你根本没执行查询当然不会抛异常...能catch到你才见鬼了...
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,