[問題] 連SQL SERVER沒問題,但無法切換資料庫?
各位好
目前在看一支程式(程式碼在最後)
目前使用正常,但問題在於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://www.ptt.cc/bbs/C_Sharp/M.1401151895.A.79D.html
→
05/27 08:55, , 1F
05/27 08:55, 1F
推
05/27 13:03, , 2F
05/27 13:03, 2F
→
05/28 22:48, , 3F
05/28 22:48, 3F
C_Sharp 近期熱門文章
PTT數位生活區 即時熱門文章