2013-04-08 87 views
0

我有一個嵌套的gridview和它的可編輯。雖然它使用訪問作爲測試目的的數據源,但我想用mysql數據源來部署它。我意識到有什麼不對。我的Gridview必須在搜索被點擊時顯示。 這是我原來的訪問數據源代碼:綁定子Gridview

//This procedure prepares the query to bind the child GridView 
private AccessDataSource ChildDataSource(string strCustometId, string strSort) 
{ 
    string strQRY = ""; 
    AccessDataSource dsTemp = new AccessDataSource(); 
    dsTemp.DataFile = "App_Data/BV.mdb"; 
    strQRY = "Query statement"; 

    dsTemp.SelectCommand = strQRY; 
    return dsTemp; 
} 

我改變以適應MySQL用戶。

private SqlDataSource ChildDataSource(string strCustometId, string strSort) 
{ 
    string strQRY = ""; 
    SqlDataSource dsTemp = new SqlDataSource(); 
    dsTemp.ID = "dsTemp"; 

    string sCon= WebConfigurationManager.ConnectionStrings["bv"].ConnectionString; 
    dsTemp.ConnectionString = sCon; 
    strQRY = "Query stament here"; 
dsTemp.SelectCommand = strQRY; 
    return dsTemp; 
} 

這是來自web.config的我的連接字符串。

<connectionStrings> 
    <add name="bv" connectionString="server=localhost;database=cms;Connect Timeout=30;Persist Security Info=False;User id = root;password=xxxxx" providerName="MySql.Data.MySqlClient"/> 

第二個代碼給出了錯誤,並表示用戶登錄失敗「根」。我的連接字符串和數據源代碼有問題。我沒有經驗,請在這方面需要幫助。

+0

您需要向我們顯示您的連接字符串。你可以檢查[ConnectionStrings.com](http://connectionstrings.com)的例子,有一堆。 – jadarnel27 2013-04-08 12:48:09

+0

感謝您的答覆。我編輯了代碼。檢查了connectionString.com網站,並使用了他們的指導方針。 – 2013-04-08 12:54:50

回答

0

您需要確保SQL Server使用您在連接字符串中指定的密碼爲用戶「root」登錄,並且用戶'root'具有必要的權限以訪問' cms'數據庫。

+0

我沒有使用SQL Server。我正在使用Mysql。 – 2013-04-08 14:01:00

+0

@SitheloNgwenya使用SqlDataSource連接到MySQL可以嗎?我以爲只是連接到SQL Server,但我可能是錯的。我不使用MySQL。 – jadarnel27 2013-04-08 14:11:11

+0

SqlDataSource只連接到SQL Server。如果您使用的是MySQL,那麼您將需要使用OleDbDataSource。 – FastGeek 2013-04-08 14:16:03