Home All Groups Group Topic Archive Search About

Access asp:SqlDataSource or asp:GridView directly

Author
5 Oct 2006 7:39 PM
saturnius
Hello, I have to save the data from a gridview as XML file. The code is
shown below. Is there no easier way? I would like to access either
asp:SqlDataSource (me.SqlDataSource1.something) or asp:GridView
(me.GridView1.something) instead I have to create a new
sqlcon,selectcommand,dataset,dataadapter....

Is there no easier way?



Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs)

'too much code?

Dim conSave As New
System.Data.SqlClient.SqlConnection(Me.SqlDataSource1.ConnectionString)
conSave.Open()
Dim strSQL As String
Dim dsSave As New Data.DataSet
Dim daSave As New Data.SqlClient.SqlDataAdapter
strSQL = Me.SqlDataSource1.SelectCommand.ToString
daSave.SelectCommand = New System.Data.SqlClient.SqlCommand(strSQL,
conSave)
daSave.Fill(dsSave)

'too much code!

dsSave.WriteXml("C:\SomeXMLFile.xml")
End Sub

Author
6 Oct 2006 3:48 AM
Cor Ligthert [MVP]
Saturnius

I don't see any GridView in your code?
You are saving a file that you have got from a database.

Cor

<saturn***@gmx.net> schreef in bericht
Show quoteHide quote
news:1160077171.762023.316080@c28g2000cwb.googlegroups.com...
> Hello, I have to save the data from a gridview as XML file. The code is
> shown below. Is there no easier way? I would like to access either
> asp:SqlDataSource (me.SqlDataSource1.something) or asp:GridView
> (me.GridView1.something) instead I have to create a new
> sqlcon,selectcommand,dataset,dataadapter....
>
> Is there no easier way?
>
>
>
> Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
> System.EventArgs)
>
> 'too much code?
>
> Dim conSave As New
> System.Data.SqlClient.SqlConnection(Me.SqlDataSource1.ConnectionString)
> conSave.Open()
> Dim strSQL As String
> Dim dsSave As New Data.DataSet
> Dim daSave As New Data.SqlClient.SqlDataAdapter
> strSQL = Me.SqlDataSource1.SelectCommand.ToString
> daSave.SelectCommand = New System.Data.SqlClient.SqlCommand(strSQL,
> conSave)
> daSave.Fill(dsSave)
>
> 'too much code!
>
> dsSave.WriteXml("C:\SomeXMLFile.xml")
> End Sub
>
Author
6 Oct 2006 7:49 PM
saturnius
Hello Cor,
I just jused drag and drop in Visual Web developer for
asp:SqlDataSource and asp:GridView - nothing else. The code behind a
button is shown above. I am just looking for a better solution to save
the xml file based on the gridview. But I can not figure out how to
access the gridview that I have on my page, instead I have to pull the
data again from the db. I would like to replace the code between my
comments by accessing the gridview/sqldatasource.

Thanks,
Saturnius
Author
7 Oct 2006 1:59 AM
Cor Ligthert [MVP]
Saturnius,

I know no other answer that putting the data you put in your gridview in
advance in a seesion.
Than you can interact with the key presses or what else with that gridview.

The session gives you than the current data in the gridview.

Cor

<saturn***@gmx.net> schreef in bericht
Show quoteHide quote
news:1160164186.916976.150340@k70g2000cwa.googlegroups.com...
> Hello Cor,
> I just jused drag and drop in Visual Web developer for
> asp:SqlDataSource and asp:GridView - nothing else. The code behind a
> button is shown above. I am just looking for a better solution to save
> the xml file based on the gridview. But I can not figure out how to
> access the gridview that I have on my page, instead I have to pull the
> data again from the db. I would like to replace the code between my
> comments by accessing the gridview/sqldatasource.
>
> Thanks,
> Saturnius
>
Author
8 Oct 2006 11:09 PM
saturnius
Hi Cor,
thank you for the answer. I guess I will stick with my "pulling twice"
.....

Thanks!
Saturnius



Cor Ligthert [MVP] wrote:

Show quoteHide quote
> Saturnius,
>
> I know no other answer that putting the data you put in your gridview in
> advance in a seesion.
> Than you can interact with the key presses or what else with that gridview.
>
> The session gives you than the current data in the gridview.
>
> Cor
>
> <saturn***@gmx.net> schreef in bericht
> news:1160164186.916976.150340@k70g2000cwa.googlegroups.com...
> > Hello Cor,
> > I just jused drag and drop in Visual Web developer for
> > asp:SqlDataSource and asp:GridView - nothing else. The code behind a
> > button is shown above. I am just looking for a better solution to save
> > the xml file based on the gridview. But I can not figure out how to
> > access the gridview that I have on my page, instead I have to pull the
> > data again from the db. I would like to replace the code between my
> > comments by accessing the gridview/sqldatasource.
> >
> > Thanks,
> > Saturnius
> >