|
![](/images/resource/spacer.gif) |
|
insert into image type ole object C# Access windowsapp |
|
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
ผมต้องการ insert รูปลง ฐานข้อมูล ต้องทำยังไงบ้างครับ
อันนี้ผมทำแล้วมัน Error
Code (C#)
private void button1_Click(object sender, EventArgs e)
{
try
{
byte[] img = null;
FileStream fs = new FileStream(pic, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
img = br.ReadBytes((int)fs.Length);
string sql = "insert into test (ID,Username,Pic) VALUES("+textBox1.Text+"'+'"+textBox2.Text+"',@pic)";
if (con.State != ConnectionState.Open) con.Open();
cmd = new OleDbCommand(sql, con);
cmd.Parameters.Add(new OleDbParameter("@pic", img));
int x = cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show(x.ToString()) ;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
Error ส่วนนี้ครับ cmd.Parameters.Add(new OleDbParameter("@pic", img));
แล้วถ้า insert เข้าไปในถานข้อมูลได้แล้ว ถ้าผมต้องการเอา รูปออกจาก ฐานข้องมูล Access ออกมา อีกทำยังไงครับ
ขอบคุณอย่างสูง
Tag : .NET, Ms Access, Win (Windows App), C#, Windows
![](/images/adv.jpg?v=1001)
|
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2016-09-25 13:55:49 |
By :
snowman0020 |
View :
933 |
Reply :
3 |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
ลองใช้อันนี้ดูนะครับ
Code (C#)
private void button1_Click(object sender, EventArgs e)
{
try
{
byte[] img = null;
FileStream fs = new FileStream(pic, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
img = br.ReadBytes((int)fs.Length);
string sql = "insert into test (ID,Username,Pic) VALUES(@id,@username,@pic)";
if (con.State != ConnectionState.Open) con.Open();
cmd = new OleDbCommand(sql, con);
cmd.Parameters.Add(new OleDbParameter("@id",textBox1.Text));
cmd.Parameters.Add(new OleDbParameter("@username", textBox2.Text));
cmd.Parameters.Add(new OleDbParameter("@pic", img));
int x = cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show(x.ToString()) ;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2016-09-25 16:07:38 |
By :
bigsuntat |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
![](/images/bbcode/grin.gif?v=1001)
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2016-09-26 09:25:48 |
By :
mr.win |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
|
|
|
![](/images/digitalocean-banner.jpg)
|
Load balance : Server 03
|