绑定一个孩子Gridview

时间:2013-04-08 12:41:43

标签: c# asp.net gridview

我有一个嵌套的gridview并且可编辑。虽然它使用access作为其数据源用于测试目的,但我想用mysql数据源部署它。我意识到有些事情是错的。我的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"/>

第二个代码给出错误,并说用户'root'登录失败。我的连接字符串和数据源代码有问题。我缺乏经验,请在此帮助。

1 个答案:

答案 0 :(得分:0)

您需要确保SQL Server具有用户“root”的登录名,其中包含您在连接字符串中指定的密码,并且还要确保用户“root”具有访问“cms”中对象的必要权限'数据库。