Welcome Guest Search | Active Topics | Sign In | Register

constructing DML SQL: insert update delete with the GRID Options
mark836
Posted: Thursday, May 8, 2008 6:43:24 AM
Rank: Member
Groups: Member

Joined: 5/1/2008
Posts: 16
Hi,

I am try to find the most elegant, effiecient way of constructing the dml sql statments using your grid. What I would like to do in term of steps is:

1. put DML table fields in string collection
field1, field2, etc.
2. use string collection to construct sql select statement and bind it to the grid (so far, so good)
note: I have additonal fields I set the width to 0 so that they don't appear. They are the primary keys to a table. I must keep their original values for update and delete sql statements. If a better way, please let me know.)

3. use string collection to construct sql update statement
note: problem because currently, don't know how to determine field type so I can put quotes around fields that need for the sql clause. (datetime, string,...) Datatype set to "auto" does not give me the type.

Perhaps a datatable? If you have an answer, can u please provide a specific example of your explanation? I am postive this will help many others besides myself.

Thank you so much for your time.
eo_support
Posted: Thursday, May 8, 2008 6:52:52 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,221
Hi Mark,

As for #2, you do not need an additional column. Grid supports a KeyField property that is specially designed for this purpose:

http://www.essentialobjects.com/ViewDoc.aspx?t=EO.Web.Grid.KeyField.html

As for #3, you can get the data type by checking the type of GridCell.Value. The Grid keeps the value types when it comes back to the server. So if the database has a DataTime value, you will see GridCell.Value as a DateTime value; if the database has a string value, you will see GridCell.Value as a string value.

Hope this helps.

Thanks
mark836
Posted: Thursday, May 8, 2008 7:02:24 AM
Rank: Member
Groups: Member

Joined: 5/1/2008
Posts: 16
The keyfield property holds a value. However, my primary key is multi field. Would u still suggest this as an option?
What do u think about my solution? Common or just dumb?

BTW, great tool. Kudos to your group and look forward to future releases.
eo_support
Posted: Thursday, May 8, 2008 7:10:08 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,221
Hi Mark,

Using a hidden field is definitely not dumb, it's a very creative solution. :) We suggesged using keyField because KeyField is purely data, so it has no UI overhead. If you have multiple fields, you can use some kind of mechanism to bind them together to form one value, for example, you can use "1|2" to represent two separate values "1" and "2".

Glad to hear you like our product. Please help to spread the word. :)

Thanks
mark836
Posted: Thursday, May 8, 2008 7:23:06 AM
Rank: Member
Groups: Member

Joined: 5/1/2008
Posts: 16
Possible future suggestion is to make keyfield as a collection?

I think I may try the datable route and get/set from a grid. It gives me more options. Or is that old school?
eo_support
Posted: Thursday, May 8, 2008 7:34:26 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,221
Thanks for suggesting making KeyField a collection. We will think about it.

We believe DataTable is a good option because it pretty much has everything you need.
mark836
Posted: Thursday, May 8, 2008 12:08:49 PM
Rank: Member
Groups: Member

Joined: 5/1/2008
Posts: 16
Hi,
by mentioning using the key field, I guess you need to loop thru each record. So, binding to the grid is different and need to bind each row to a grid row. How is that accomplished?

Thanks


example

while (reader.Read())
{
?? bind to grid?

}
conn.Close();
conn.Dispose();
eo_support
Posted: Thursday, May 8, 2008 12:17:51 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,221
No. You do:

Grid1.DataSource = reader;
Grid1.DataBind();

The Grid does the loop for you and creates one GridItem for each record, and also put the value of KeyField for each record to each GridItem's Key property.

Thanks
mark836
Posted: Thursday, May 8, 2008 12:28:53 PM
Rank: Member
Groups: Member

Joined: 5/1/2008
Posts: 16
unfortunately, this is a problem.
the keyfield property is not being populated by using

Grid1.DataSource = reader;
Grid1.DataBind();

So, I was assuming I need to fill in the key property by myself. Which means I need to loop thru the dataGrid and the kefield property or how is this accomplished?

Thanks
eo_support
Posted: Thursday, May 8, 2008 12:42:47 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,221
Hi Mark,

In that case I would check whether KeyField is correctly set. You can also take a look of this sample:

http://www.essentialobjects.com/Demo/Default.aspx?path=Grid\_i1\_i5

This sample uses KeyField. You can load the source code in Visual Studio and compare it with yours.

Thanks
mark836
Posted: Thursday, May 8, 2008 12:50:47 PM
Rank: Member
Groups: Member

Joined: 5/1/2008
Posts: 16
Not to be ungrateful for your help but this example youhave linked does not show the code only the runtime. I guess I must search thru all the downloaded examples to try to find the code. I know that this must seem annoying to you, but the keyfield propery is not being set (right or wrong) and therefore, must do it myself. There are no examples of this?

This
eo_support
Posted: Thursday, May 8, 2008 1:14:12 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,221
Hi Mark,

Full source code for all the samples are already installed on your machine when you install our product (provided in Visual Studio projects). You can load the sample project and run it on your own machine.

I am not exactly sure what you mean by "the keyfield propery" is not being set. It works this way:

1. You set the Grid's KeyField property. For example, if you have a "item_id" field in your database and that is your key field, you would set the Grid's KeyField property to "item_id". In another word, you should set Grid.KeyField;
2. You will then be able to use access GridItem.Key property. This property contains the value of the key field you set on step 1. For example, if user changed an item's name on the client side, you will then be able to tell exactly which item's name has been changed by examing the changed item's Key property. For example, if the item’s Key property is “3”, you will be able to say the item whose “item_id” is 3 has been changed;

For more information, you will want to go over the help file. Just like the same code, it's also available on your local machine as a .chm file.

Hope this helps.

Thanks
mark836
Posted: Thursday, May 8, 2008 1:24:03 PM
Rank: Member
Groups: Member

Joined: 5/1/2008
Posts: 16
Ouch! House of bricks just fell on me. I know now.. you set the keyfield by a field name, not the value.

Thanks again for the help.


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.