Link to home
Start Free TrialLog in
Avatar of samir25
samir25

asked on

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

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
Avatar of renjurdevan
renjurdevan
Flag of India image

dt.Columns("a") or dt.Columns(0)

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

Regards
Renju
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


Avatar of samir25
samir25

ASKER

can i use the above before  da.Fill(dt) or after?
Avatar of samir25

ASKER

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'.
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
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

Avatar of samir25

ASKER

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
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
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
Avatar of samir25

ASKER

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.      
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
Avatar of samir25

ASKER

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?
Avatar of samir25

ASKER

where xdoc would be
 Set xdoc = CreateObject("MSXML2.DOMDocument.4.0")  
    xdoc.async=false
your last question is not clear to me!!

Regards
Renju
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



Avatar of samir25

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of renjurdevan
renjurdevan
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of samir25

ASKER

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.
Avatar of samir25

ASKER

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
;)  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
Avatar of samir25

ASKER

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
Avatar of samir25

ASKER

the error that was coming went away ... as suddenly it came equally surprising it disappeared. is it an vs.net limitation or what?
Avatar of samir25

ASKER

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
Avatar of samir25

ASKER

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
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
Avatar of samir25

ASKER

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
Avatar of samir25

ASKER

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

woudl this process make it faster?