我正在尝试做以下事情:
- 将新图片添加到数据库中(添加到名为“PicProfile”的列中)。
- 将路径/位置复制到文本框(名为 image_path_txt)。另外,我可以用除图像之外的其他字段添加记录。
有人可以告诉我我做错了什么吗?
private void button1_Click(object sender, EventArgs e)
{
byte[] imageBT = null;
FileStream fstream = new FileStream(this.image_path_txt.Text, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fstream);
imageBT = br.ReadBytes((int)fstream.Length);
string constring = "datasource=localhost;port=3306;username=root;password=amg135468lns";
string Query = "insert into db.newuser (FName,LName,Age,Gender,Phone_No, Mobile_No,City, Street, Street_No,Email,idNewUser,PicProfile)"+ "values('" + this.Fname_txt.Text + "','" + this.Lname_txt.Text + "','"+this.Age_txt.Text+"','"+this.Gender+"','" + this.Phone_txt.Text + "','" + this.Mobile_txt.Text + "','" + this.City_txt.Text + "','" + this.Street_txt.Text + "','" + this.StreetNo_txt.Text + "','" + this.Email_txt + "','"+this.user_no_txt.Text+"',@PicP);";
MySqlConnection conDataBase = new MySqlConnection(constring);
MySqlCommand cmdDataBase = new MySqlCommand(Query,conDataBase);
MySqlDataReader myReader;
try
{
conDataBase.Open();
cmdDataBase.Parameters.Add(new MySqlParameter("@PicP", imageBT));
myReader = cmdDataBase.ExecuteReader();
MessageBox.Show("Saved");
while (myReader.Read())
{
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}