作者Competitive (...)
看板C_Sharp
标题[问题] 连SQL SERVER没问题,但无法解换资料库?
时间Tue May 27 08:51:32 2014
各位好
目前在看一支程式(程式码在最後)
目前使用正常,但问题在於SqlConnection
("server=(local)\\SQLEXPRESS;database=abc;uid=sa;password=abc"
在SQL SERVER中还有另一个资料库为abc2
但我的SQLEXPRESS中的database如果改为abc2,仍会连abc
请问在C#中切换资料库还要作什麽处理吗?
还是函式中CALL的DATABASECONNECT()其实是另一只程式的
问题很菜很浅,但仍请指教
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;
namespace AAA
{
public partial class AddEmp : System.Web.UI.Page
{
protected DataSet myDataSet;
SqlConnection conn;
SqlCommand cmd;
protected void Page_Load(object sender, EventArgs e)
{
if (Session["EmpID"] == null)
{
Response.Write("<script>window.parent.location.href='Logon.aspx';</script>");
}
else
{
if (!IsPostBack)
{
Button1.Attributes["onclick"] = "javascript:return
confirm('确定加入?');";
InitDropItems();
bind();
}
}
}
private void DatabaseConnect()
{
conn = new
SqlConnection("server=(local)\\SQLEXPRESS;database=abc;uid=sa;password=abc");
conn.Open();
}
protected void InitDropItems()
{
try
{
DatabaseConnect();
//煦?蹈桶
SqlCommand tmpcmd = new SqlCommand("Select * from DropItems
where ItemName='煦?' and Visible=1", conn);
tmpcmd.CommandType = CommandType.Text;
SqlDataAdapter tmpadp = new SqlDataAdapter();
tmpadp.SelectCommand = tmpcmd;
DataSet tmpds = new DataSet("ddlTeam");
tmpadp.Fill(tmpds);
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 210.69.124.41
※ 文章网址: http://webptt.com/cn.aspx?n=bbs/C_Sharp/M.1401151895.A.79D.html
1F:→ Competitive:是否像JSP一样其实要先编译成CLASS才能运作? 05/27 08:55
2F:推 johnpage:连线字串怪怪的 05/27 13:03
3F:→ netnk:conn.close() 05/28 22:48