Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help... C# SQLite Opendialog file lock

Status
Not open for further replies.

caixadelixo

Programmer
Aug 24, 2013
1
PT
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);
}
}

}


}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top