MSDOTnet.org Forum Index
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[VC++] Insert binary files into Odbc MySQL connection!!

 
Post new topic   Reply to topic    MSDOTnet.org Forum Index -> ODBC Dotnet
Author Message
alexfont



Joined: 08 Aug 2007
Posts: 1

PostPosted: Tue Dec 05, 2006 3:25 pm    Post subject: [VC++] Insert binary files into Odbc MySQL connection!! Reply with quote

Hello,

I've post on main MSDN foruns and they forward to me this newsgroup. They
didn't help me at all to fix my problem, so I hope here, someone could give
me a tip of what I'm doing wrong.

I'm using the following code to send a binary file into MySQL database using
Odbc and VC++:

OdbcConnection ^db = gcnew
OdbcConnection("Dsn=iDigitalConnection;server=localhost;database=iDigital;uid=root");

db->Open();

FileStream ^fs;
BinaryReader ^bin;

fs = gcnew FileStream("C:\\database.dat", FileMode::Open, FileAccess::Read);

bin = gcnew BinaryReader(fs);
cli::array ^file = bin->ReadBytes((int)fs->Length);

bin->Close();
fs->Close();

String ^queryStr = "INSERT INTO dbress (filecontent, filesize) VALUES
(@DBFileContent,@DBFileSize)";

OdbcCommand ^myCmd = gcnew OdbcCommand(queryStr, db);

myCmd->Parameters->Add("@DBFileContent", OdbcType::Binary,
file->Length)->Value = file;
myCmd->Parameters->Add("@DBFileSize", OdbcType::BigInt, 20)->Value =
file->Length;

myCmd->ExecuteNonQuery();
db->Close();

This code runs but it put NULL data into the database. It doesn't pass
"@DBFileContent" and "@DBFileSize" and replace it with the right values.

I've read for MySQL we should use '?' instead of '@' but that doesn't help
at all.

Any help in this matter???

Thanks in advance and hope here something for you soon Wink,
Alexandre

Archived from group: microsoft>public>dotnet>framework>odbcnet
Back to top
View user's profile Send private message
Display posts from previous:   
Related Topics:
"Connection is dead" on ODBC insert of decimal into DB2 I am having problems inserting Decimal values into a DB2 database via a .NET/C# application which is using an Other field types such as VarChar, Int, Date, etc work ok, and I can insert literal values into a decimal field, but any attempt

ODBC.NET & MYSQL Can I connect to MYSQL databases using ODBC.NET? How?

MySQL ODBC ASP.NET Hi I got an website and it has got MySQL Database and it has only ODBC Connection setting. I have created the database in the web as "conn", username as "conn321" and password as I am using ASP.NET. Can any one give me the

ODBC could not find MYSQL 3.51 driver Hi, I am having a problem with connecting to MySQL driver from ODBC. I can see from ODBC datasource that MySQL Driver is there and I can test successfully. But when I try to connect from ODBC, I received the error that MySQL ODBC Driver can not be foiund

MySQL ODBC Driver Not Found Hi, I have an ASP.NET project (2.0) I want to be able to access a MySQL database. I use a connection string like this: ODBC 3.51 Zero This
Post new topic   Reply to topic    MSDOTnet.org Forum Index -> ODBC Dotnet All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group