Home All Groups Group Topic Archive Search About

Perform insert to gridview/table

Author
15 Mar 2006 10:51 PM
Bernie Niblets
Hello Group,

I am working with VS2005 and asp.net 2.0.

I would like to perform an insert to a table/gridview by clicking a
button on a web form (not part of the gridView rendering).  I can do
this using the VS2003 methods of sqldataadapter, etc by running the
insert, etc, but without the handy "visual" control in VS2003.  Can I do
a similar thing using the sqldatasource, and having it hooked to a
gridview?  I do not want to use the "embedded" feature of the gridview
for inserting, etc.


can i perform a programatic insert using the sqldatasource?

Any info will help,

Thanks,

eric

Author
15 Mar 2006 11:19 PM
Andrew Robinson
Eric,

There is no native ability in the GridView to insert data, only update and
delete.

If you take a look at my blog, I have an entry there that shows how to get
around this. If you only want to get this functionality out of the Sql Data
Adaptor, you will find that the events and methods of the Sql Adaptor are
just about the same as the Data Adaptor which I write about in the same
entry on my blog.

Hope this helps,

http://blog.binaryocean.com/InsertRowsWithAGridViewII.aspx

-Andrew

--

Andrew Robinson
http://blog.binaryocean.com


Show quoteHide quote
"Bernie Niblets" <e.m***@verizon.net> wrote in message
news:121h6qkhi8lljf7@corp.supernews.com...
> Hello Group,
>
> I am working with VS2005 and asp.net 2.0.
>
> I would like to perform an insert to a table/gridview by clicking a button
> on a web form (not part of the gridView rendering).  I can do this using
> the VS2003 methods of sqldataadapter, etc by running the insert, etc, but
> without the handy "visual" control in VS2003.  Can I do a similar thing
> using the sqldatasource, and having it hooked to a gridview?  I do not
> want to use the "embedded" feature of the gridview for inserting, etc.
>
>
> can i perform a programatic insert using the sqldatasource?
>
> Any info will help,
>
> Thanks,
>
> eric
Author
16 Mar 2006 10:42 PM
Bernie Niblets
Andrew Robinson wrote:
Show quoteHide quote
> Eric,
>
> There is no native ability in the GridView to insert data, only update and
> delete.
>
> If you take a look at my blog, I have an entry there that shows how to get
> around this. If you only want to get this functionality out of the Sql Data
> Adaptor, you will find that the events and methods of the Sql Adaptor are
> just about the same as the Data Adaptor which I write about in the same
> entry on my blog.
>
> Hope this helps,
>
> http://blog.binaryocean.com/InsertRowsWithAGridViewII.aspx
>
> -Andrew
>
Hello Andrew,

I will check it out!

thankss
Author
16 Mar 2006 12:46 PM
CaffieneRush@gmail.com
Yes you can do a programmatic insert.
Suppose you have a LinkButton called btnInsert, a list of input
Textboxes to get the information for the insert and a SqlDataSource
called sqldatasource1 that has been properly setup with InsertCommand,
InsertParameters etc.

Within the click event handler of btnInsert, gather all the information
from your input textboxes and assign them to the
sqldatasource.InsertParameters collection.
Finally call sqldatasource1.Insert()

'Small example
Protected Sub btnInsert_Click(sender As Object, args As EventArgs)
  sqldatasource1.InsertParameters("Col1").DefaultValue = TextBox1.Text
  sqldatasource1.InsertParameters("Col2").DefaultValue = TextBox2.Text

  Page.Validate("InsertGroup")
  If Page.IsValid Then
    sqldatasource1.Insert
  End If
End Sub

Good luck.