Previous Topic

Next Topic

How a New Profile Is Added

Clicking the Add button in the application triggers the execution of the profileAddButton_Click event handler.

Note: This example uses the ingresInsertCommand6, which was created when the ingresDataAdapter6 was added.

The query used is as follows:

INSERT into user_profile VALUES ( next value FOR up_id, ?, ?, ?, ?, ? )

You can write this query using the Query Designer for the IngresCommand by changing the CommandText property, or assign it directly to the IngresCommand CommandText property as a string.

The values are assigned into a data table cloned from the user_profile table in the ProfileDataSet.

DataTable dataTable = profileDataSet.Tables["user_profile"].Clone();

DataRow dataRow = dataTable.NewRow();

The values to be added are taken from the profile form controls and used as parameters to the query.

dataRow["up_last"] = lastName;

dataRow["up_first"] = firstName;

dataRow["up_email"] = email;

dataRow["up_airport"] = airport;

if (photoFile.Length > 0)

{

    MemoryStream stream = new MemoryStream();

    Image photo = System.Drawing.Image.FromFile(photoFile);

    photo.Save(stream, photo.RawFormat);

    dataRow["up_image"] = stream.ToArray();

    stream.Close();

}

The path and file name of the image are used to convert it into a Byte array and read into the up_image column.

The new row is added to the data table which is used in the INSERT command.

dataTable.Rows.Add(dataRow);

ingresDataAdapter6.InsertCommand.Parameters.Clear();

ingresDataAdapter6.InsertCommand.Parameters.Add("@up_last",

    Ingres.Client.IngresType.NVarChar, "up_last");

ingresDataAdapter6.InsertCommand.Parameters.Add("@up_first",

    Ingres.Client.IngresType.NVarChar, "up_first");

ingresDataAdapter6.InsertCommand.Parameters.Add("@up_email",

    Ingres.Client.IngresType.NVarChar, "up_email");

ingresDataAdapter6.InsertCommand.Parameters.Add("@up_airport",

    Ingres.Client.IngresType.NChar, "up_airport");

ingresDataAdapter6.InsertCommand.Parameters.Add("@up_image",

    Ingres.Client.IngresType.LongVarBinary, "up_image");

resAffected = ingresDataAdapter6.Update(dataTable);

The added parameters link the parameter values to the columns in the data table. The data table is used in the update method to add the new row.


© 2006 Ingres Corporation. All rights reserved.