1、大家看看我这么写有问题吗?
2、2005和2003连接数据库的代码有区别吗?using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
SqlConnection myConn = new SqlConnection();
string strConn = "server=localhost;uid=sa;pwd=;database=pubs";
myConn.ConnectionString = strConn;
myConn.Open();
Response.Write("<script language='javascript'> alert ('连接成功!')</script>");
myConn.Close();
}
catch
{
Response.Write("<script language='javascript'> alert ('连接失败!')</script>");
}
}
}
2、2005和2003连接数据库的代码有区别吗?using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
SqlConnection myConn = new SqlConnection();
string strConn = "server=localhost;uid=sa;pwd=;database=pubs";
myConn.ConnectionString = strConn;
myConn.Open();
Response.Write("<script language='javascript'> alert ('连接成功!')</script>");
myConn.Close();
}
catch
{
Response.Write("<script language='javascript'> alert ('连接失败!')</script>");
}
}
}
解决方案 »
- 记录上一页地址
- SQL 子查询问题
- 这个语句如何理解?
- 如何给网站加MSN接口
- |M| 自已帮别人做了一个网上商城,但现在他想要添加多点功能,但因为原来的代码写得很乱,改成来很是麻烦,现在我想问一下大家在做网上商城的
- 救急!!!!!!!!关于excel的 ,比较有难度
- 请教:在B/S里怎样定义一个在一个页面里使用的局部变量
- TreeView高手请进(查询数据库生成Xml文件,再绑定到TreeView控件上)在线等!!!
- 发现ASP.NET里表单验证的时候有矛盾!!大家进来瞧瞧.
- The process cannot access the file ,it is being used by another process.
- 如何禁止事件不可单击?
- 使用XPATH读取 DOMDocument 节点内容
1、string strConn = "server=服务器IP;uid=sa;pwd=;database=pubs";
2、string strConn = "server=服务器名称;uid=sa;pwd=;database=pubs";当然登陆的用户名你要确保正确
try
{
SqlConnection myConn = new SqlConnection();
string strConn = "server=localhost;uid=sa;pwd=z;database=pubs";
myConn.ConnectionString = strConn;
myConn.Open();
Response.Write("<script language='javascript'> alert ('连接成功!')</script>");
myConn.Close();
}
catch(SqlException ex)
{
Response.Write("<script language='javascript'> alert ('连接失败!')</script>");
this.Label1.Text = ex.ToString();
}