user3780731
user3780731

Reputation: 95

Adding image as a parameter of a method

I have a C# winform application with a database. In the database I have one DataTable called Airlines. The columns of this DataTable are "Name", "Country", "Telephone", "Email", "Logo".

I want to create a method to be used in Windows Form application. This method is going to be

public int AddNewAirline (string name, string country, string telephone, string email, xxxxx)

The parameters will be taken from Windows Form text boxes, and the logo by the Browse... option. I have created the method and the SQL operation is:

"INSERT INTO Airlines VALUES('"+name+"','....blah blah blah.... ¿but what about the logo? )";

So my main question, is: What parameter should I add on the xxxxxx part of the method header, and what the SQL operation should be like? I'm a bit messed with this and I couldn't find a solution on the Internet.

Upvotes: 0

Views: 212

Answers (1)

Ben
Ben

Reputation: 152

In order to store the path to the image in the database, you can do it the same way you are saving the other parameters:

public int AddNewAirline (string name, string country, string telephone, string email, string logoPath)

You SQL insert statement is missing the column names. Try this:

"INSERT INTO Airlines ('Name', 'Country', 'Telephone', 'Email', 'Logo') " +
"VALUES ('" + name + "', '" + country + "', '" + telephone + "', '" + email + "', '" + logoPath + "')"

You should be aware that in taking this approach, the possibility exists that the image could be moved or deleted, leaving your database with a path to a file that no longer exists. In order to resolve this, you could make a copy of the image to a safe location and reference the copy in your database, or you could store the actual bytes of the image in your database as a BLOB.

Upvotes: 1

Related Questions