0

I have a file I converted into one long string. I want to take that string, convert it to a array of bytes then upload it to my database. However, when i run my code, it shows up in the database as NULL;

Here's my code:

SQL.UploadFile(Encoding.ASCII.GetBytes(FBX), txt_Name.Text);

        public void UploadFile(byte[] value, string Where)
    {

        const string SQL = "UPDATE itemmodel SET modelFile='@File' WHERE modelName='@Name'";
        MySqlCommand cmd = new MySqlCommand(SQL, MySqlCon);
        cmd.Parameters.AddWithValue("@File", value);
        cmd.Parameters.AddWithValue("@Name", Where);
        MySqlCon.Open();
        cmd.ExecuteNonQuery();
        MySqlCon.Close();

    }

1 Answer 1

2

I really don't think that you want the quotes around the parameters in the SQL:

const string SQL = "UPDATE itemmodel SET modelFile=@File WHERE modelName=@Name";

Certainly not around @File.

Sign up to request clarification or add additional context in comments.

3 Comments

Okay thank you that worked. Now how can i return the byte array to a c# string? When i return the query just to a string i only get the first few words
I'm not very familiar with MySQL, but you should be able to just SELECT it out (i.e. SELECT fileModel FROM itemModel WHERE xxx); the .Net framework/MySQL driver should return the column as a byte array.
One of the variants is to create a MySqlCommand with SELECT query, call MySqlCommand.ExecuteReader to get reader, then read records one by one - IDataReader.Read() and read data you need - IDataReader.GetBytes...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.