为什么我连接的数据库和我查询的表不一样却可以链接成功?
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