Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.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#_Sql_Database_Picturebox - Fatal编程技术网

C# 从已读图片框更改背景

C# 从已读图片框更改背景,c#,sql,database,picturebox,C#,Sql,Database,Picturebox,1。) 我得到了一个表格,其中我得到了110个PictureBox,在我的数据库中我得到了这些行:attacktype,role,pictureboxname。在攻击类型中,我有近战或远程攻击,角色还不重要,并且行:pictureboxname包含(pictureBox1,pictureBox2)手动写入其中 所以我的读者确实选择了每一行类型为近战。我想让这些选定的图片框隐藏在表单上,我该怎么做?按如下操作 private void mELEEToolStripMenuItem_Clic

1。)

我得到了一个表格,其中我得到了110个PictureBox,在我的数据库中我得到了这些行:attacktype,role,pictureboxname。在攻击类型中,我有近战或远程攻击,角色还不重要,并且行:pictureboxname包含(pictureBox1,pictureBox2)手动写入其中

所以我的读者确实选择了每一行类型为近战。我想让这些选定的图片框隐藏在表单上,我该怎么做?

按如下操作

    private void mELEEToolStripMenuItem_Click(object sender, EventArgs e)
    {
        SqlDataReader reader = null;
        SqlConnection cn = new SqlConnection(global::vaja15.Properties.Settings.Default.Database1ConnectionString);
        cn.Open();
        SqlCommand sda = new SqlCommand("SELECT * FROM Uporabnik WHERE attacktype='melee' ", cn);
        reader = sda.ExecuteReader();


            while (reader.Read())
            {
                label1.Text = reader[7].ToString();
            }

            reader.Close();

        cn.Close();
    }
您的命令必须是:

cmd.Parameters.AddWithValue("@mele",melee).Value = melee (if melee is string  type "melee")

我在这里添加了一些东西:我的想法是,当我单击此菜单项时,会发生以下情况:pictureBox1.Hide();pictureBox2.Hide();但仅针对所选图片框我在何处插入您写入的第一行?您能否发送您最后写入的内容?抱歉,使用sda更改cmd,因为您使用sda作为命令。通常我使用的是SqlCommand cmd=newsqlcommand:))sda.Parameters.AddWithValue(“@melee”,melee)。Value=melee(如果近战是字符串类型的“melee”);显示错误如果近战是字符串类型,你应该写“近战”,如果它是数字,你必须写近战
 SqlCommand sda = new SqlCommand("SELECT * FROM Uporabnik WHERE attacktype=@melee", cn);