In the table users a MySql db for each user can be stored with a different color, for example:
Users colors
Foo green
Pluto yellow
Foo red
When the user is authenticated I need to know what color is associated with the user who logs on.
I used the List method to append the variable color for each user in this way:
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());
}
And everything works up here.
Now I need publish in a GridView all rows stored in Experience table where are stored the comments of all users for each color.
For example in the case of user Foo I need publish in GridView all comments stored in Experience table speaking of the colors red and green.
But I can't publish this GridView because if user is Foo I see only the comments on the red color and nothing comment for green color.
Thought with loop I have this output:
SELECT * FROM Experience WHERE Colors IN ('red');
SELECT * FROM Experience WHERE Colors IN ('green');
My code below.
Anybody know how can I resolve do this?
Can you suggest?
Can you help me?
Thank you in advance.
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;
}
Edit # 1
Users colors
Foo green
Pluto yellow
Foo red
Aucun commentaire:
Enregistrer un commentaire