Upload image directly through mySQL Command Line

前端 未结 6 1100
春和景丽
春和景丽 2020-12-18 19:12

I have a certain table in mySQL which has a field called \"image\" with a datatype of \"BLOB\". I was wondering if it is possible to upload an image in that field directly f

6条回答
  •  被撕碎了的回忆
    2020-12-18 19:44

    It is more preferable to build a sample application and then insert the values in the database. For instance this method could be used to enter a BLOB datatype into the database...

    [WebMethod]
                    public string sendDataToMySql(string get_name, byte[] buffer)
                    {
                        string MyConString = "SERVER=localhost;" +
                              "DATABASE=test;" +
                              "UID=root;" +
                              "PASSWORD=admin;";
    
    
                        MySqlConnection connection = new MySqlConnection(MyConString);
                        connection.Open();
                        MySqlCommand command = new MySqlCommand("", connection);
                        command.CommandText = "insert into testImage(name, image) values(@name, @image);";
    
    
                        MySqlParameter oParam1 = command.Parameters.Add("@name", MySqlDbType.VarChar, 50);
                        oParam1.Value = get_name;
    
    
                        MySqlParameter oParam2 = command.Parameters.Add("@image", MySqlDbType.Blob);
                        oParam2.Value = buffer;
    
                        command.ExecuteNonQuery();
    
                        connection.Close();
                        return "Data was inserted successfully!";
                       }
    

提交回复
热议问题