S
Sampath Gamaarchchi
Guest
I have used below code to insert student id and picture to my sql database and got an error message and appreciate your assistance.
…….MySQL table creation...
create table mst_image (student_id varchar(11) not null,foreign key(student_id) references mst_student(student_id),image longblob not null);
…..error......
MySql.Data.MySqlClient.MySqlException: 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'student_mgt.insert into mst_image(student_id,image) values ('04190319003',_binar' at line 1'
…..c# coding.....
private void button4_Click(object sender, EventArgs e)
{
MySqlCommand cmd;
FileStream fs;
BinaryReader br;
string FileName = txtStudentImage.Text;
byte[] ImageData;
fs = new FileStream(FileName, FileMode.Open, FileAccess.Read);
br = new BinaryReader(fs);
ImageData = br.ReadBytes((int)fs.Length);
br.Close();
fs.Close();
string CmdString = "student_mgt.insert into mst_image(student_id,image) values (@id,@image)";
cmd = new MySqlCommand(CmdString, conn);
cmd.Parameters.Add("@id", MySqlDbType.VarChar, 11);
cmd.Parameters.Add("@image", MySqlDbType.LongBlob);
cmd.Parameters["@id"].Value = txtbx_prntid.Text;
cmd.Parameters["@image"].Value =picbx_vwid.Image;
conn.Open();
int RowsAffected = cmd.ExecuteNonQuery();
if (RowsAffected > 0)
{
MessageBox.Show("Image saved sucessfully!");
}
conn.Close();
}
Continue reading...
…….MySQL table creation...
create table mst_image (student_id varchar(11) not null,foreign key(student_id) references mst_student(student_id),image longblob not null);
…..error......
MySql.Data.MySqlClient.MySqlException: 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'student_mgt.insert into mst_image(student_id,image) values ('04190319003',_binar' at line 1'
…..c# coding.....
private void button4_Click(object sender, EventArgs e)
{
MySqlCommand cmd;
FileStream fs;
BinaryReader br;
string FileName = txtStudentImage.Text;
byte[] ImageData;
fs = new FileStream(FileName, FileMode.Open, FileAccess.Read);
br = new BinaryReader(fs);
ImageData = br.ReadBytes((int)fs.Length);
br.Close();
fs.Close();
string CmdString = "student_mgt.insert into mst_image(student_id,image) values (@id,@image)";
cmd = new MySqlCommand(CmdString, conn);
cmd.Parameters.Add("@id", MySqlDbType.VarChar, 11);
cmd.Parameters.Add("@image", MySqlDbType.LongBlob);
cmd.Parameters["@id"].Value = txtbx_prntid.Text;
cmd.Parameters["@image"].Value =picbx_vwid.Image;
conn.Open();
int RowsAffected = cmd.ExecuteNonQuery();
if (RowsAffected > 0)
{
MessageBox.Show("Image saved sucessfully!");
}
conn.Close();
}
Continue reading...