How insert image to mysql ,I using visual c++/CLI

Hello,
I write code using visual c++/CLI
to insert image to mysql .
But it show errors,
It show (parameter is not valid)!!
Can anyone help me??
Last edited on
Sure, post your code between [code]/* your code here */[/code] tags.
Use the <> icon on the format panel to the right, or just type them in.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
String^ con=L"datasource=localhost; port=3306;username=root; password=411126;";
             MySqlConnection ^ conn=gcnew MySqlConnection(con);
             MySqlCommand^ cmd=gcnew MySqlCommand("select img from info.images where id='"+textBox1->Text+"'",conn);
             MySqlDataReader^re;
             try{
                 conn->Open();
                 re=cmd->ExecuteReader();
                 re->Read();
                 BinaryFormatter^fe=gcnew BinaryFormatter();
                 BinaryFormatter();
                 MemoryStream^ms=gcnew MemoryStream();
                 fe->Serialize(ms,re["img"]);
                 array<Byte>^arr =ms->ToArray();
                 MemoryStream^ms2=gcnew MemoryStream(arr);
                 pictureBox1->Image=Image::FromStream(ms2);
             }
             catch(Exception^ex){
                 MessageBox::Show(ex->Message,"ERROR");
             }
does it say where? Is it not liking the string sql statement?
Last edited on
It say on line this,
pictureBox1->Image=Image::FormStrem(ms2);
ok, so either the statement that created ms2 above had a problem (perhaps arr has a problem) OR it is the wrong type of parameter or something for the call. Not sure, I don't speak the xor dialect of c++ (IS this c++?!) , but that is my best guess on where to start looking.
Last edited on
I have no idea what this is, but I googled your code and came up with this stack overflow post from 2016, maybe it helps:

https://stackoverflow.com/questions/37083359/how-can-i-retrieve-my-image-from-mysql-in-visual-c-cli

jonnin wrote:
I don't speak the xor dialect of c++ (IS this c++?!)
It's Microsoft's C++\CLI managed form of C++ (basically, C++ w/ .NET).
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
con = gcnew MySqlConnection("datasource=localhost; port=3306; username=root; password=41556126;");
			String^ selectQuery = "select * from info.images where id='"+textBox1->Text+"'";
            cmd = gcnew MySqlCommand(selectQuery, con);
            adp = gcnew MySqlDataAdapter(cmd);
            DataTable^ table = gcnew DataTable();
            adp->Fill(table);

			MySqlDataReader ^ mr;
			con->Open();
			mr=cmd->ExecuteReader();
			
            if (table->Rows->Count == 0)
            {
                pictureBox1->Image = nullptr;
                MessageBox::Show("Data not found!");
            }
            else
            {
			
                byte[] img = (byte[])table->Rows[0][1];
                MemoryStream ^ ms = gcnew MemoryStream(img);
                pictureBox1->Image = Image::FromStream(ms);
				con->Close();
            }
It show error on this words (byte,[] , img, img)

how fix error?
Topic archived. No new replies allowed.