检索错误(参数无效),但我的列名是图像
本文关键字:我的 图像 错误 参数 无效 检索 | 更新日期: 2023-09-27 18:03:42
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(Helper.ConnectionString);
SqlCommand cmd = new SqlCommand();
string sql = string.Format("select empid,empname,salary,gender,image from emp where empid = {0}",comboBox1.Text);
cmd.CommandText = sql;
cmd.Connection = con;
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
int indid = dr.GetOrdinal("empid");
int indname = dr.GetOrdinal("empname");
int indsalary = dr.GetOrdinal("salary");
int indgender = dr.GetOrdinal("gender");
while (dr.Read())
{
int id = dr.GetInt32(indid);
textBox1.Text = id.ToString();
textBox2.Text = dr.GetString(indname);
textBox3.Text = dr.GetDecimal(indsalary).ToString();
string gen = dr.GetString(indgender);
if (gen == "Male")
radioButton1.Checked = true;
else
radioButton2.Checked = true;
byte[] imgg = (byte[])(dr["image"]);
if (imgg == null)
pictureBox1.Image = null;
else
{
using
(MemoryStream mstream = new MemoryStream(imgg))
pictureBox1.Image = System.Drawing.Image.FromStream(mstream);
}
}
con.Close();
}
'image'作为列名无效。你需要'[image]':
select empid,empname,salary,gender,[image] from emp where empid = {0}
另外,我建议你搜索"SQL Injection"来了解为什么你的代码是危险的。