473,402 Members | 2,064 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Access asp:SqlDataSource or asp:GridView directly

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.SqlDataSour ce1.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

Oct 5 '06 #1
4 1476
Saturnius

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

Cor

<sa*******@gmx.netschreef in bericht
news:11**********************@c28g2000cwb.googlegr oups.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.SqlDataSour ce1.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

Oct 6 '06 #2
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

Oct 6 '06 #3
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

<sa*******@gmx.netschreef in bericht
news:11**********************@k70g2000cwa.googlegr oups.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

Oct 7 '06 #4
Hi Cor,
thank you for the answer. I guess I will stick with my "pulling twice"
.....

Thanks!
Saturnius

Cor Ligthert [MVP] wrote:
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

<sa*******@gmx.netschreef in bericht
news:11**********************@k70g2000cwa.googlegr oups.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
Oct 8 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Gord D via AccessMonster.com | last post by:
I have a small ASP website with an Access2000 database. Seems someone has found it and INSERTS records into a table by typing the URL and not via web page/form. I know this as I have some...
7
by: WayDownUnder | last post by:
Hello, I have a gridview control bound to a objectdatasource. The primary key column is on the grid but made visible = false. Because the column is invisible I cant get to the cell value when the...
4
by: WayDownUnder | last post by:
I am trying to findout which column the user clicked on in a gridview. column 0 = CommandField ( view) column 1 = CommandFiled ( edit) When the event grdTemp_SelectedIndexChanged occurs on...
9
by: ghostwolf | last post by:
Hi, I want to hide a column in the asp:GridView, say one of the column of asp:BoundField. But it is not allowed to put <divinside for setting it display:none. What can I do? Thanks in millions.
11
by: tbh | last post by:
is it possible in the ConnectionString of an asp:SqlDataSource construction to refer to a variable i define at the top of my ASPX script and initialize, for example, during Page_Init()? (the...
1
by: sheenaa | last post by:
Hello Members, I m creating my application forms in ASP.Net 2005 C# using the backend SQL Server 2005. What i have used on forms :: ? On my first form i have used some...
0
by: jumpinjavabean | last post by:
I have an (ASP.NET 2.0) asp:GridView control and I want to be able to control the relative display position of each column. For example, let's say I have four columns in the datasource and I want...
1
by: =?Utf-8?B?R3JlZw==?= | last post by:
I have a <asp:GridViewcontrol that is populated with records. The first column I display contains a "UserID" DataField. I've created my column using the following code: <asp:BoundField...
5
AnuSumesh
by: AnuSumesh | last post by:
Hi All, I am using <asp:Gridview> to display my data. I am adding columns and rows dynamically. I am facing following issues: 1. I want scrollbars around the gridview and for this purpose i...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.