?
Solved

v.urgent:how to refer the column name in dataadapter

Posted on 2007-07-22
27
Medium Priority
?
267 Views
Last Modified: 2010-04-16
hi
how can i refer the table column.
like i have this query select a,b from table.
i use it as
 Using da As New OracleDataAdapter(FCommand)
                     Try
                            FConnection.Open()
                            da.Fill(dt)
i want to use the table column a specifically ... how can i do that?
thanks
0
Comment
Question by:samir25
  • 15
  • 12
27 Comments
 
LVL 12

Expert Comment

by:renjurdevan
ID: 19545450
dt.Columns("a") or dt.Columns(0)

dt.Columns("b") or dt.Columns(1)

Regards
Renju
0
 
LVL 12

Expert Comment

by:renjurdevan
ID: 19545456
dt.Rows(RowNumber)(column index or name)

like

dt.Rows(0)("a")  Or dt.Rows(0)(0)

dt.Rows(0)("b")  Or dt.Rows(0)(1)

Regards
Renju


0
 
LVL 1

Author Comment

by:samir25
ID: 19545493
can i use the above before  da.Fill(dt) or after?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 1

Author Comment

by:samir25
ID: 19545497
it doesnt solve my purpose :-(

FConnection.Open()
                            Dim xmlDoc As New XmlDocument
                            Dim OracleClob As OracleClob
                            da.Fill(dt)
                            xmlDoc = dt.Columns(7)
                            xmlDoc.LoadXml(xmlDoc)
i get this error
Value of type 'System.Data.DataColumn' cannot be converted to 'System.Xml.XmlDocument'.
0
 
LVL 12

Expert Comment

by:renjurdevan
ID: 19545502
yes !! if you want to loop thru rows

you can use like

For i = 0 To dt.Rows.Count - 1

a = dt(i)("a")
b = dt(i)("b")

Next

if you are operating with string appending use StringBuilder!! otherwise it may hit perfomance

Regards
Renju
0
 
LVL 12

Expert Comment

by:renjurdevan
ID: 19545518
above "a" and "b" are strings !!

Get the value in strings and try load it into XmlDocument
like

string xmlDoc = dt(i)("a")

XmlDocument objXmlDoc = New XmlDocument ()

objXmlDoc.LoadXml(xmlDoc)              ' FYI::: where xmlDoc is string data

Regards
Renju

0
 
LVL 1

Author Comment

by:samir25
ID: 19545528
sorry i am not too clear. i am referring 8 columns in my query and hence it should be dt.columns(7). why shoudl i refer to rows. can you pls help write exactly what steps to follow
0
 
LVL 12

Expert Comment

by:renjurdevan
ID: 19545555
You should mention the row which you are fetching data!!

dt.columns(7) will return a datacolumn collection!! not the data from column 7!!

to get a data you shld use like

string strData = dt(0)(7)   Here you will get 7Th column data from 0th Row

You may have more than 1 rows present in your table so you shld specify the row number,  which you want to fetch data

Regards
Renju
0
 
LVL 12

Expert Comment

by:renjurdevan
ID: 19545590
FConnection.Open()
                            Dim szData as STring
                            Dim xmlDoc As New XmlDocument
                            Dim OracleClob As OracleClob
                            da.Fill(dt)
                            szData = dt.(0)(7)            ' Assuming that you hav only one row and first row contains data
                            xmlDoc.LoadXml(szData)


Regards
Renju
0
 
LVL 1

Author Comment

by:samir25
ID: 19545606
ok here is what i did
Using FCommand As New OracleCommand(query, FConnection)
                    Dim da As New OracleDataAdapter(FCommand)
                    Try
                        FConnection.Open()
                        Dim xmlDoc As String
                        da.Fill(dt)
                        Dim objXmlDoc As New XmlDocument
                        For i = 0 To dt.Rows.Count - 1
                            xmlDoc = dt(i)("xml_data")
                            objXmlDoc.LoadXml(xmlDoc)
                        Next
                        FConnection.Close()
                        FCommand.Dispose()
                        FConnection.Dispose()
and i get below error on dt(i)("xml_data")

Class 'System.Data.DataTable' cannot be indexed because it has no default property.      
0
 
LVL 12

Expert Comment

by:renjurdevan
ID: 19545631
i extreamly sorry i missed the key word "row"

xmlDoc = dt.Rows(i)("xml_data")

FYI:: here each and every iteration xml is being loaded into objXmlDoc!!


Regards
Renju
0
 
LVL 1

Author Comment

by:samir25
ID: 19545654
yes error is not there.
can you help me some more of your expert inputs.
in asp i had xf.LoadXML(xdoc.selectSingleNode("//Error").xml)...and i would refer the node of the xml.her how can i do in asp.net
xf.LoadXML(xdoc.selectSingleNode("//Error").xml)
objXmlDoc.loadXML(????.SelectSingleNode("//Error").xml)

and then i need to refer this particular column to the gridview. how can i do that?
0
 
LVL 1

Author Comment

by:samir25
ID: 19545660
where xdoc would be
 Set xdoc = CreateObject("MSXML2.DOMDocument.4.0")  
    xdoc.async=false
0
 
LVL 12

Expert Comment

by:renjurdevan
ID: 19545664
your last question is not clear to me!!

Regards
Renju
0
 
LVL 12

Expert Comment

by:renjurdevan
ID: 19545677
well the flow is like

xmlDoc = dt.Rows(i)("xml_data") ' getting sting xml

objXmlDoc.LoadXml(xmlDoc) ' Load that string into XmlDocument object infact in memory

Dim XmlNode objNode = objXmlDoc.selectSingleNode("//Error")


Regards
Renju



0
 
LVL 1

Author Comment

by:samir25
ID: 19545678
i want to extract a node from the xml(which is an error node) and put it the string in the gridview column. i already bind the grid as GridView1.DataBind() and i refer each datafield in the aspx page.

but now i want to do 2 things
1. extract the node content from the xml file and
2. show is gridview
0
 
LVL 12

Accepted Solution

by:
renjurdevan earned 2000 total points
ID: 19545695

xmlDoc = dt.Rows(i)("xml_data") ' getting sting xml

objXmlDoc.LoadXml(xmlDoc) ' Load that string into XmlDocument object infact in memory

Dim XmlNode objNode = objXmlDoc.selectSingleNode("//Error")

string data = objNode.InnerText               '  will return the data


Regards
Renju
0
 
LVL 1

Author Comment

by:samir25
ID: 19545696
well how do you know all this. if you searched on this then pls tell me how do you seacrch for this kind of help. its frustating to not know all this small stuff. once u know it seems small..and once u dont its big.

how do i refer it in the grid column.
0
 
LVL 1

Author Comment

by:samir25
ID: 19545708
i am getting this error on using the above
ORA-06502: PL/SQL: numeric or value error
 Dim xData As String
 For i = 0 To dt.Rows.Count - 1
                            xmlDoc = dt.Rows(i)("xml_data")
                            objXmlDoc.LoadXml(xmlDoc)
                            objNode = objXmlDoc.SelectSingleNode("//Error")
                            xData = objNode.InnerText
                        Next
0
 
LVL 12

Expert Comment

by:renjurdevan
ID: 19545739
;)  Get a book on Asp.Net  .. seems like a fresher in this domain!!


To bind these values in grid column do it in RowBinding even  of grid view !! use template column


http://www.codeproject.com/useritems/create_template_columns.asp
http://msdn2.microsoft.com/en-us/library/ms228046.aspx

Regards
Renju
0
 
LVL 1

Author Comment

by:samir25
ID: 19545744
i removed the innertext change adn still i am getting error. here is the error i get
ORA-06503: PL/SQL: Function returned without value
ORA-06512: at "PackageName.ProcName", line 39

this error was not comign bef but nowits coming.
basically i am referrign to a view where xml_data is this
PackageName.ProcName.blob2clob(compressor.blob_decompress(xml_data)) as XML_DATA
0
 
LVL 1

Author Comment

by:samir25
ID: 19545779
the error that was coming went away ... as suddenly it came equally surprising it disappeared. is it an vs.net limitation or what?
0
 
LVL 1

Author Comment

by:samir25
ID: 19545798
no i am not a fresher. its just job scope which keeps changing. i was working on asp.net 2 yrs back. and then started workign on diff tech. now my work again involves asp.net. all this small small things i already struggled b4 but unfortunatley i forget easily. maybe concepts not clear. but i didnt work on xml before
0
 
LVL 1

Author Comment

by:samir25
ID: 19545974
this is coming out to be extremely slow. bec ia m referring to all the xml files which are huge. i never had this issue with asp. they were fast. is there anything i can do to make it fast
0
 
LVL 12

Expert Comment

by:renjurdevan
ID: 19546047
as far your code is concern you are reading xml documents for each iteration

how many Rows you have in data table?
depends upon the rows time may increase!!
i dont know what you are trying to achive with this code or i hardly understood ur situation!!

Regards
Renju
0
 
LVL 1

Author Comment

by:samir25
ID: 19546078
ok ... i am basically providing the user the id and couple of other things from table in which error has occured. the xml file contains the content why the error occured. so apart from table data i need to show one node from xml file (for each record there is one xml file)..in my case error files are around 300
0
 
LVL 1

Author Comment

by:samir25
ID: 19546098
here is another way to refer xml ..
http://www.oracle.com/technology/pub/articles/price_dotnet2.html

woudl this process make it faster?
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question