caixadelixo
Programmer
Hi, way it dosent work????? Form 2 button open, save.... It only works if fileDialog
is comented out and pass the string directly. Eg. filepath =@"image.jpg";
public partial class Form1 : Form
{
string conecxao = "Data Source=MovieData.s3db";
int idRecord = 2;
string filepath = null;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
if (dlg.ShowDialog() == DialogResult.OK)
{
filepath = dlg.FileName;
}
}
private void button2_Click(object sender, EventArgs e)
{
byte[] MyData = null;
FileStream fs = new FileStream(filepath, FileMode.OpenOrCreate, FileAccess.Read);
MyData = new byte[fs.Length];
fs.Read(MyData, 0, System.Convert.ToInt32(fs.Length));
fs.Close();
if (idRecord > 0)
{
SQLiteConnection conn = new SQLiteConnection(conecxao);
if (conn.State == ConnectionState.Closed) { conn.Open(); }
SQLiteCommand cmd = new SQLiteCommand("UPDATE FilmsDB SET picCoverDB=@picCoverDB WHERE idFilm=@idFilm ", conn);
cmd.Parameters.AddWithValue("idFilm", idRecord);
cmd.Parameters.AddWithValue("picCoverDB", MyData);
try
{
cmd.ExecuteNonQuery();
MessageBox.Show("Cover successfully updated.");
}
catch (Exception ex)
{
MessageBox.Show("Error updating cover." + ex.Message);
}
}
}
}
is comented out and pass the string directly. Eg. filepath =@"image.jpg";
public partial class Form1 : Form
{
string conecxao = "Data Source=MovieData.s3db";
int idRecord = 2;
string filepath = null;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
if (dlg.ShowDialog() == DialogResult.OK)
{
filepath = dlg.FileName;
}
}
private void button2_Click(object sender, EventArgs e)
{
byte[] MyData = null;
FileStream fs = new FileStream(filepath, FileMode.OpenOrCreate, FileAccess.Read);
MyData = new byte[fs.Length];
fs.Read(MyData, 0, System.Convert.ToInt32(fs.Length));
fs.Close();
if (idRecord > 0)
{
SQLiteConnection conn = new SQLiteConnection(conecxao);
if (conn.State == ConnectionState.Closed) { conn.Open(); }
SQLiteCommand cmd = new SQLiteCommand("UPDATE FilmsDB SET picCoverDB=@picCoverDB WHERE idFilm=@idFilm ", conn);
cmd.Parameters.AddWithValue("idFilm", idRecord);
cmd.Parameters.AddWithValue("picCoverDB", MyData);
try
{
cmd.ExecuteNonQuery();
MessageBox.Show("Cover successfully updated.");
}
catch (Exception ex)
{
MessageBox.Show("Error updating cover." + ex.Message);
}
}
}
}