I was creating a program that can insert audio into mysql database(i am using mediumblob data type) but when i click insert button it showed an error "column data cannot be null". Here is my code :
private void buttonBrowse_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "WAV Audio Files|*.wav|M4A Audio Files|*.m4a";
if (ofd.ShowDialog() == DialogResult.OK)
{
textBoxBrowse.Text = ofd.FileName;
}
}
private void buttonSimpan_Click(object sender, EventArgs e)
{
OdbcConnection con = new OdbcConnection(Program.konek);
OdbcCommand com = new OdbcCommand("insert into audio(data) values(@voice)", con);
byte[] stream = File.ReadAllBytes(@textBoxBrowse.Text);
MessageBox.Show(stream.ToString());
if (stream.Length > 0)
{
com.Parameters.AddWithValue("@voice", stream);
con.Open();
int result = com.ExecuteNonQuery();
if (result > 0)
MessageBox.Show("insert done");
con.Close();
}
}
Does anyone have a solution for this ?