views:

128

answers:

1

I'm trying to insert a record into a table without using the SubSonic object in a VB.Net Windows app. (It will take too long to explain why.)

Dim q As New SubSonic.Query("tablename") q.QueryType = SubSonic.QueryType.Insert q.AddUpdateSetting("Description", txtDescription.Text) q.Execute()

This just updates all the rows in the table. I read in one post that instead of AddUpdateSetting, I should use AddWhere, but that didn't make any sense to me. I don't need a where clause at all.

Searching for all:QueryType.Insert at subsonicproject.com didn't return anything (which I thought was weird).

Can anyone tell me how to fix this query? Thanks!

A: 

Do you use ActiveRecord? The best way is just to create a new SubSonic generated object and call the Save method.

Product p = new Product();
p.Description = "Hello World";
p.Save();

Update:

I just checked it. At least in SubSonic2 you can use this piece of code:

   DB.Insert() _
        .Into(TableObject.Schema, TableObject.Columns.Description) _
        .Values(txtDescription.Text) _
        .Execute()
SchlaWiener
Oh, yeah. We use active record all the time. This particular form is meant to edit several similar tables. So, instead of taking the dropdown selection value to figure out which active record object to make, I thought I'd just have the table name as the dropdown's value and update the table with a generic query.
Darkwater23