你好我想在没有数据类型大小的C#中从MySQL中检索LONGBLOB,但只有数据类型longblob.i可以保存在mysql中使用longblob但我可以再次检索它。
我在其中创建了一个名为'dataalis'的表,
CREATE TABLE `Wajah`.`dataalis` (
`No` int(10) unsigned NOT NULL auto_increment,
`Nama` varchar(45) default NULL,
`Keterangan` varchar(600) default NULL,
`Gambar` longblob,
PRIMARY KEY (`No`)
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8;
和
nama = namatxt.Text;
keterangan = keterangantxt.Text;
db = new DBConnect();
FileStream fs = new FileStream(location, FileMode.Open, FileAccess.Read);
int fileLength = (int)fs.Length;
byte[] rawdata = new byte[fileLength];
fs.Read(rawdata, 0, (int)fileLength);
MySqlCommand cmd = new MySqlCommand();
String sql = "insert into dataalis (Nama,Keterangan,Gambar) values(@Nama,@Keterangan,@Gambar)";
cmd.Connection = db.getConnection();
cmd.CommandText = sql;
cmd.Parameters.AddWithValue("@Nama", nama);
cmd.Parameters.AddWithValue("@Keterangan", keterangan);
cmd.Parameters.AddWithValue("@Gambar", rawdata);
int result = cmd.ExecuteNonQuery();
fs.Close();
MessageBox.Show("Data Tersimpan","Peringatan");
将图像保存到mysql
我尝试使用此代码检索longblob图像
MySqlCommand cmd = new MySqlCommand();
cmd.Connection = db.getConnection();
cmd.CommandText = "select * from datamulut";
data = cmd.ExecuteReader();
while (data.Read())
{
int fileSize = data.GetInt32(data.GetOrdinal("size"));
string name = data.GetString(data.GetOrdinal("Keterangan"));
byte[] rawData = new byte[fileSize];
data.GetBytes(data.GetOrdinal("Gambar"), 0, rawData, 0, fileSize);
MemoryStream ms = new MemoryStream(rawData);
images.Add(Image.FromStream(ms));
gambar1.Image = images[0];
hasil1txt.Text = (name);
}
data.Close();
在该代码中我不使用文件大小数据只有longblob.how我可以检索图像而不用filezie只有longblob数据?