Insert using oleDbAdapter

  • Thread starter Thread starter irabadan
  • Start date Start date
I

irabadan

Hello, I'm trying to implement a very easy asp.net page to insert some
data in a database. I'm doing it using as less code as posible so I
used as much data controls as possible. Here is the page schema:

3 Textfields
1 button
1 oleDbConnection
1 oleDbAdapter (link to the connector) with an insert statement.
1 dataSet (generated from the adapter)

Each textbox is bind to the dataset using the DataBindings
properties.

In the button click code behind I have this code:

oleDbConnection1.Open();
dataSet11.AcceptChanges();
oleDbDataAdapter1.Fill(dataSet11,"Usuarios");
oleDbDataAdapter1.Update(dataSet11,"Usuarios");
oleDbConnection1.Close();

I expect the textbox data to be inserted in the database when the code
is executed but there is no item inserted.

If I use: oleDbDataAdapter1.InsertCommand.ExecuteNonQuery(); one row
is inserted in the database but no with the textbox values but with
the default ones.

Any idea what I'm doing wrong?

Thanks

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
 
I have associated the text box with the dataset using the databinding
propertie in design so I think that when you insert a value in the
textbox it is automatically inserted in the data set, isn't it? Maybe
I should do something manually but I don't know what...

Thank you Miha

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
 
Hi,

There are problems with this:
- asp.net databinding is readonly sort of binding (no, the value isn't
written back to dataset)
- your code does Fill and then immediately Update - no time to write
anything into dataset.
 
So, how can I use the insert statement for the adapter? What I want is
to do it with as less code as possible. I can do it using an SQL
insert statement like: "Insert into books
Values(')"+TextBox1.Text+"')"; and it works but what is the purpose
of the adpater?

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
 
Back
Top