用stream和Tblod
procedure TForm1Button1Click(Sender: TObject);
var stream:TMemoryStream;
begin
try
stream:=TADOBlobStreamCreate;
with ADOQuery1 do
begin
close;
sqltext:='select from tp where bh='+QuotedStr(Text1);
open;
TBlobField(FieldByName('photo'))SaveToStream(stream);
imgPictureBitmapLoadFromStream(stream);
close;
end;
finally
streamFree;
end;
end;
image1PictureBitmapSaveToStream(stream);
image2CanvasDraw(0,0,Image1PictureBitmap);
with adotable1 do
begin
close;
Open;
edit;
TBlobField(adotable1FieldByName('image'))LoadFromStream(stream);
post;
TBlobField(adotable1FieldByName('image'))SaveToStream();
// image2PictureBitmapAssign();
end;
finally
streamFree;
end;
end;
using System;
using SystemCollectionsGeneric;
using SystemComponentModel;
using SystemData;
using SystemDataSqlClient;
using SystemDrawing;
using SystemText;
using SystemWindowsForms;
namespace DataSource
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private DataSet ds = new DataSet();
private SqlConnection conn = null;
private SqlDataAdapter da = null;
private const string DRIVER = "server=;database=northwind;uid=sa;pwd=sa";
private const string sql_select = "select from region";
/
此方法为将数据库northwind中的region表的数据查询出来并放入DataSet中
/
private void Form1_Load(object sender, EventArgs e)
{
conn = new SqlConnection(DRIVER);
da = new SqlDataAdapter(sql_select,conn);
daFill(ds,"table");
thisdataGridView1DataSource = dsTables["table"]DefaultView;
}
private bool BtnInsert() //此方法作用于添加
{
daInsertCommand = connCreateCommand();
daInsertCommandCommandText = "insert into region values(@id,@ption)";
daInsertCommandParametersAdd("@id", SqlDbTypeInt, 4, "regionid");
daInsertCommandParametersAdd("@ption", SqlDbTypeVarChar, 10, "regiondescription");
int count = daUpdate(ds);
bool result = count > 0 true : false;
return result;
}
private void button1_Click(object sender, EventArgs e)
{
if (thisBtnInsert())//调用此方法
{
MessageBoxShow("添加成功!");
}
else
{
MessageBoxShow("添加失败!");
}
}
private bool BtnDelect() //此方法作用于删除
{
SqlParameter sp = new SqlParameter();
daDeleteCommand = connCreateCommand();
daDeleteCommandCommandText = "delete region where regionid=@id";
sp = daDeleteCommandParametersAdd("@id", SqlDbTypeInt, 4, "regionid");
spSourceVersion = DataRowVersionOriginal;
dsTables["table"]Rows[thisdataGridView1CurrentRowIndex]Delete();
int count = daUpdate(ds);
bool result = count > 0 true : false;
return result;
}
private void button2_Click(object sender, EventArgs e)
{
if (thisBtnDelect())//调用删除方法
{
MessageBoxShow("删除成功!");
}
else
{
MessageBoxShow("删除失败!");
}
}
private bool BtnUpdate() //此方法作用于修改
{
SqlParameter sp = new SqlParameter();
daUpdateCommand = connCreateCommand();
daUpdateCommandCommandText = "update region set regionid=@id,regiondescription=@ption where regionid=@oldid";
daUpdateCommandParametersAdd("@id", SqlDbTypeInt, 4, "regionid");
daUpdateCommandParametersAdd("@ption", SqlDbTypeVarChar, 10, "regiondescription");
sp = daUpdateCommandParametersAdd("@oldid", SqlDbTypeInt, 4, "regionid");
spSourceVersion = DataRowVersionOriginal;
int count = daUpdate(ds);
bool result = count > 0 true : false;
return result;
}
private void button3_Click(object sender, EventArgs e)
{
if (thisBtnUpdate())//调用修改方法
{
MessageBoxShow("修改成功!");
}
else
{
MessageBoxShow("修改失败!");
}
}
}
}
以上就是关于delphi中如何把Image控件导入到数据库中全部的内容,包括:delphi中如何把Image控件导入到数据库中、如何把datagridview控件中一行数据导入SQLSERVER数据库中、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)