Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 绑定子Gridview_C#_Asp.net_Gridview - Fatal编程技术网

C# 绑定子Gridview

C# 绑定子Gridview,c#,asp.net,gridview,C#,Asp.net,Gridview,我有一个嵌套的gridview,它是可编辑的。尽管出于测试目的,它使用access作为数据源,但我希望使用mysql数据源部署它。我意识到出了问题。单击搜索时必须显示我的Gridview。 这是我的原始access数据源代码: //This procedure prepares the query to bind the child GridView private AccessDataSource ChildDataSource(string strCustometId, string str

我有一个嵌套的gridview,它是可编辑的。尽管出于测试目的,它使用access作为数据源,但我希望使用mysql数据源部署它。我意识到出了问题。单击搜索时必须显示我的Gridview。 这是我的原始access数据源代码:

//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”登录失败。我的连接字符串和数据源代码有问题。我没有经验,请在这方面寻求帮助。

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

您需要向我们显示您的连接字符串。你可以查看示例,有很多。谢谢你的回复。我已经编辑了代码。也检查了connectionString.com网站,并使用了他们提供的指南。我没有使用SQL Server。我正在使用Mysql。@SitheloNgwenya使用SqlDataSource连接到Mysql可以吗?我以为这只是连接到SQL Server,但我可能错了。我不使用MySQL。SqlDataSource只连接到SQLServer。如果您使用的是MySQL,那么您将需要使用OLEDB数据源。我有.NET连接器,这使我能够连接到MySQL。我在使用SqlDataSource组件之前安装了它。是的,经过一段时间的阅读,我发现可以使用带有适当连接器的MySQL的SqlDataSource-很好!您是否已检查您在连接字符串中指定的用户root的密码是否正确?并且用户root至少对cms数据库具有select权限?