insert image path in access database (winform access)
Code (C#)
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
open.InitialDirectory = "C:\\";
open.Filter = "Image File (*.jpg)|*.jpg|All Files(*.*)|*.*";
open.FilterIndex = 1;
if (open.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
if (open.CheckPathExists)
{
OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\PEERAKIT\source\repos\WindowsFormsApp1\WindowsFormsApp1\imagepath.accdb; Persist Security Info = False; ");
string CorrectFilename = System.IO.Path.GetFileName(open.FileName);
OleDbCommand cmd = new OleDbCommand("INSERT INTO xxx (ID,path) values ((Select isnull(Max(Id),0) + 1 from xxx),'\\image\\" + CorrectFilename + "')", con);
cmd.ExecuteNonQuery();
con.Close();
string path = Application.StartupPath.Substring(0, (Application.StartupPath.Length - 10));
System.IO.File.Move(open.FileName, path + "\\image\\" + CorrectFilename);
MessageBox.Show("Successfully Uploaded");
}
}
}
Error น่าจะเปิดจากการเขียน insert ไม่รู้ว่าผิดตรงส่วนไหน
Type ของ ID = number path = short text
ขอบคุณมากๆครับTag : .NET, Ms Access, Win (Windows App), C#, VS 2017 (.NET 4.x), Windows
Date :
2018-04-29 18:14:01
By :
snowman0020
View :
813
Reply :
2
Code (C#)
OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\PEERAKIT\source\repos\WindowsFormsApp1\WindowsFormsApp1\imagepath.accdb; Persist Security Info = False; ");
//เพิ่ม
con.Open();
Date :
2018-04-29 19:31:25
By :
lamaka.tor
ดูเหมือนยังไม่ได้เปิด Connection ครับ
Date :
2018-04-30 09:25:50
By :
mr.win
Load balance : Server 03