//小弟刚学,好多都是仿照别人的 ,下面是图像的获取,不知要怎么修改
openFileDialog1.ShowDialog();
try
{
FileStream fs = File.OpenRead(openFileDialog1.FileName);
content = new byte[fs.Length];
// string temp = System.Text.Encoding.Default.GetString(content);
// pictureBox1.Image = System.Drawing.Image.FromFile(openFileDialog1.FileName);
}
catch
{
pictureBox1.Image = System.Drawing.Image.FromFile(null);
}
//添加函数
private void Add()
{
string num = textBox1.Text;
if (isAdded(num))
{
MessageBox.Show("该记录已存在");
}
else
{
conn.Open();
string name = textBox2.Text;
string sex=comboBox1.Text;
MessageBox.Show(sex);
string mobile= textBox3.Text;
string qq =textBox4.Text;
string email=textBox5.Text;
string address=textBox6.Text;
// string sqlString = "insert into Student(Number,Name,Sex,Mobile,QQ,Email,Address,Image) Values("+num.ToString()+",'"+name+"'"+",'"+sex+"',"+mobile.ToString()+","+qq.ToString()+",'"+email+"','"+address+"','"+i+"'"+")";
string sqlString = "insert into classmate(Number,Name,Sex,Mobile,QQ,Email,Address,Image) Values(@Nu,@Na,@Se,@Mo,@Q,@Em,@Ad,@Im)";
cmd = new SqlCommand(sqlString, conn);
cmd.Parameters.Add(new SqlParameter("@Nu",SqlDbType.VarChar,50,"Number"));
cmd.Parameters.Add(new SqlParameter("@Na",SqlDbType.VarChar,50,"Name"));
cmd.Parameters.Add(new SqlParameter("@Se",SqlDbType.VarChar,50,"Sex"));
cmd.Parameters.Add(new SqlParameter("@Mo",SqlDbType.Decimal,50,"Mobile"));
cmd.Parameters.Add(new SqlParameter("@Q",SqlDbType.VarChar,50,"QQ"));
cmd.Parameters.Add(new SqlParameter("@Em",SqlDbType.VarChar,50,"Email"));
cmd.Parameters.Add(new SqlParameter("@Ad",SqlDbType.VarChar,50,"Address"));
cmd.Parameters.Add(new SqlParameter("@Im",SqlDbType.Image,50,"Image"));
cmd.Parameters["@Nu"].Value = num;
cmd.Parameters["@Na"].Value = name;
cmd.Parameters["@Se"].Value = sex;
cmd.Parameters["@Mo"].Value = mobile;
cmd.Parameters["@Q"].Value = qq;
cmd.Parameters["@Em"].Value = email;
cmd.Parameters["@Ad"].Value = address;
cmd.Parameters["@Im"].Value =content;
int rowsReturned = cmd.ExecuteNonQuery();
MessageBox.Show(rowsReturned.ToString()+"记录添加成功");
conn.Close();
}
}
//错误信息:参数化查询 '(@Nu varchar(50),@Na varchar(50),@Se varchar(50),@Mo decimal(7,0' 需要参数 @Im,但未提供该参数。