Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/336.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/72.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# 在c中启用多用户管理_C#_Mysql_Asp.net_Gridview - Fatal编程技术网

C# 在c中启用多用户管理

C# 在c中启用多用户管理,c#,mysql,asp.net,gridview,C#,Mysql,Asp.net,Gridview,在users表中,每个用户的MySql数据库可以用不同的颜色存储,例如: Users colors Foo green Pluto yellow Foo red 当用户通过身份验证时,我需要知道与登录的用户关联的颜色 我使用列表方法以这种方式为每个用户添加变量颜色: List<string> colorList = new List<string>(); .... if (reader.HasRows) {

在users表中,每个用户的MySql数据库可以用不同的颜色存储,例如:

Users       colors
Foo         green
Pluto       yellow
Foo         red
当用户通过身份验证时,我需要知道与登录的用户关联的颜色

我使用列表方法以这种方式为每个用户添加变量颜色:

List<string> colorList = new List<string>();

....

if (reader.HasRows)
{
    while (reader.Read())
    {
        Colors = reader["Colors"].ToString();
        colorList.Add(Colors.ToString());
    }

        ns = string.Join(", ", colorList.ToArray());
}
下面是我的代码

有人知道我该怎么做吗

你能推荐一下吗

你能帮我吗

先谢谢你

private DataSet RetrieveColors()
    {
        str = null;
        strArr = null;
        count = 0;

        str = ns == null ? "" : ns.ToString();
        char[] splitchar = { ',' };

        if (!string.IsNullOrEmpty(str))
        {
            strArr = str.Split(splitchar);
        }
        else
        {
            strArr = null;
        }

        for (count = 0; count <= strArr.Length - 1; count++)
        {
                sql = @" SELECT * FROM Experience WHERE Colors IN (?); ";
        }


        DataSet dsColors = new DataSet();

        using (OdbcConnection cn =
          new OdbcConnection(ConfigurationManager.ConnectionStrings["ConnMySQL"].ConnectionString))
        {
            cn.Open();

            using (OdbcCommand cmd = new OdbcCommand(sql, cn))
            {
                for (count = 0; count <= strArr.Length - 1; count++)
                {
                    cmd.Parameters.AddWithValue("param1", Server.UrlDecode(strArr[count].Trim()));
                }

                OdbcDataAdapter adapter = new OdbcDataAdapter(cmd);
                adapter.Fill(dsColors);
            }
        }

        return dsColors;
    }
请尝试以下代码:

sql = @" SELECT * FROM Experience WHERE Colors IN (?";

for (count = 1; count <= strArr.Length - 1; count++)
        {
                sql += ",?"; // add more placeholders as needed
        }
sql+=");"
请尝试以下代码:

sql = @" SELECT * FROM Experience WHERE Colors IN (?";

for (count = 1; count <= strArr.Length - 1; count++)
        {
                sql += ",?"; // add more placeholders as needed
        }
sql+=");"

请显示经验表列和预期输出的示例。@BlackBaron请参阅我的第一个问题中的编辑1。请显示经验表列和预期输出的示例。@BlackBaron请参阅我的第一个问题中的编辑1
sql = @" SELECT * FROM Experience WHERE Colors IN (?";

for (count = 1; count <= strArr.Length - 1; count++)
        {
                sql += ",?"; // add more placeholders as needed
        }
sql+=");"