ADODB Recordset not able to extract the 'XMLData' (xml format data) from SQL database - vbscript

I have a SQL table which is containing some xml data like below -
xmlData
I wrote a VBS code which is extract all the SQL column data excluding "XMLData"
my Dummy VBS Code -
Sub getdata()
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Connection String"
Set objRecordSet = CreateObject("ADODB.Recordset")
sqlquery = "select * from TableName WHERE IsExecute = 'Yes'"
Set rs = objConnection.Execute(sqlquery)
If Recordset.EOF Then
msgbox "There are no records to retrieve; Check that you have the correct job number."
Else
'if there are records then loop through the fields
Do While NOT Recordset.Eof
field = Recordset("xmlData")
if field <> "" then
Msgbox field
end if
Recordset.MoveNext
Loop
End Sub
Need a help to get xml format data from SQL database.
like -
***xmlData
<
EndResync/> ***
Thanks
RaviK

Related

MS Access underline text in a Table

I have long Text field in a table in MS ACCESS. I need to underline it for specific text in a field. I tried to change Text format to Rich Text in the design view , but I am getting:
Error : Operation is not supported for this type of Object
In the table I have 320 rows. I need to Underline for N.J.S.A. only in the long text.
Please help me regarding this. Thanks in Advance
Well... you have to get that field property changed from plain text to rich text for this to work and design view should handle this. If not try the below code.
Public Sub TestUnderline()
Dim db As DAO.Database
Dim tbl As DAO.TableDef
Dim fld As Field
Dim rst As DAO.Recordset
Dim strSQL As String
Dim strString As String
Set db = CurrentDb
Set tbl = db.TableDefs("Table1") 'Change to your table name
Set fld = tbl.Fields("TestField") 'Change to your field name
With fld.Properties("TextFormat")
If .Value = acTextFormatPlain Then
.Value = acTextFormatHTMLRichText
End If
End With
strSQL = "SELECT TestField " & _ 'Change to your Field name
"FROM Table1;" 'Change to your table name
Set rst = db.OpenRecordset(strSQL)
Do While Not rst.EOF
If InStr(1, rst![TestField], "N.J.S.A") Then 'Change to your field name
strString = Replace(rst![TestField], "N.J.S.A", "<u>N.J.S.A</u>") 'Change to your field name
rst.Edit
rst![TestField] = strString 'Change to your field name
rst.Update
End If
rst.MoveNext
Loop
EndCode:
If Not rst Is Nothing Then
rst.Close
Set rst = Nothing
End If
If Not tbl Is Nothing Then
Set tbl = Nothing
End If
If Not db Is Nothing Then
Set db = Nothing
End If
End Sub
Credit given to:
How to convert a text field in an Access table to a rich text memo using VBA
and:
http://www.tek-tips.com/viewthread.cfm?qid=1538917

Classic ASP Iterate through and Object

I'm a PHP developer, learning ASP.
I've become very reliant on PHP's useful functions: print_r() and var_dump() to see what an array or object contains.
I don't always know what columns are in a Db Table. So, when a SELECT * From Tbl is queried, and the objRS is populated, would I be able to view what the entire object's contents are?
Is this possible in ASP?
<% `my simple Select statement
Dim strDbConnection
Dim objConn
Dim objRS
Dim strSQL
strDbConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\test.mdb;"
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open(strDbConnection)
strSQL = "SELECT * FROM persons"
Set objRS = objConn.Execute(strSQL)
If objRS.EOF Then
Response.Write("No items found")
Else
Do While Not objRS.EOF
' show all columns I can extract here....
objRS.MoveNext()
Loop
End If
objRS.Close()
Set objRS = Nothing
objConn.Close()
Set objConn = Nothing
%>
-- I would like to see what's coming back at me in the objRS, and then cherry-pick the columns after I know what I have access to.
Is there something similar to what I'm used to?
ie: print_r()
You can use objRS.fileds(j).name and objRS.fields(j).value to get the name of columns and values.
For example:
[...]
for j = 0 to objRS.fields.count - 1
response.write(objRS.fields(j).name & " = " & objRS.fields(j).value)
next

How to deal with textbox validation?

Private Sub txtUserCode_Validate(Cancel As Boolean)
If RS!ID = txtUserCode.Text Then
SQL = "SELECT NAME,PRIVILEDGE FROM ADMIN WHERE CODE=" & txtUserCode.Text
Set RS = CN.Execute(SQL)
txtUserName.Text = RS!NAME
Else
MsgBox "ENTER VALID NO"
txtUserCode.Text = ""
Cancel = True
End If
End Sub
In this code I want to execute like:
If I enter the ID present in table then it'll show info but it's considering 1st record (RS!ID(0)) only not the next one
If I enter the ID which is not present in table then it should not throw error
3021- Requested operation requires current record but goto else part.
Please Help
I am assuming RS is a recordset.
Depending on the RS type, you can try and Find a record like this:
RS.MoveFirst
RS.Find("[CODE]=" & txtUserCode.Text)
If Not RS.EOF Then
' found!
End If
Link to the ADO Find function.

How can I create datareport using recordset in vb6?

Private Sub showreport_Click()
sql = "select * from student_record_database where"
sql=sql+ Grade='" & Combo1.Text & "' AND Meal='" & Combo11.Text & "'"
Set RES = CON.Execute(sql)
Set DataReport1.DataSource = RES
DataReport1.WindowState = vbMaximized
DataReport1.Show vbModal
End Sub
I am using this code as record set to create a data report.
My task is to choose options from various combo boxes and then display it's report so record set is needed there..
My question is that whether this code is sufficient to create data report???
I didn't set any properties of data environment or data report such as (connection - command - sql) because I am passing this record set directly to data report,then no need to fire any sql in properties of data environment.
But unfortunately it is not showing desired output
Please help me.
Try this one:
Private sub cmdprint_click()
Dim rs as new adodb.recordset
rs.open "SQL Query Statement Here",CON, adOpenDynamic, adLockOptimistic
set datareport1.datasource=rs
datareport1.show
end sub
Notes:
The data report datasouce should be cleared during design mode. (See properties on the datareport and set its datasource property to empty.) Ohhh...one more thing, please keep in mind that you should set also the datafield property for each textbox object inside the datareport corresponding to the datafield on your database during design time...
I am using this method for a long time and it works fine.
Try this.
To add a quite to a string, use a double quite.
Also you missed spelled the second Combo1 reference as Combo11
Private Sub showreport_Click()
sql = "select * from student_record_database where "
sql = sql & "Grade=""" & Combo1.Text & """ AND Meal=""" & Combo1.Text & """"
Set RES = CON.Execute(sql)
Set DataReport1.DataSource = RES
DataReport1.WindowState = vbMaximized
DataReport1.Show vbModal
End Sub

Can't access multiple records being returned by sql via ADODB.Recordset object

When I execut the sql direct it returns 4 records. when I execute the oraCommand.Execute the oraResults object shows only 1 record returned it should have a count of 4.
Hence I can get the value and name for the single record. Question is how do I get the other 3 records? I have tried set oraResults=oraResults.NextRecordSet() and I get error saying not supported!
Any help will appreciated.
This is the snippet of the code:
set oraCommand = CreateObject("ADODB.Command")
'set connection and sql statement
set oraCommand.ActiveConnection = oraConnection
oraCommand.CommandText =oraSQLStatement
oraCommand.CommandType = 1 ' commandText
oraCommand.Prepared = True
set oraResults = CreateObject("ADODB.Recordset")
'run the sql
set oraResults = oraCommand.Execute
oraResults.Fields(0).Name - Name from first record is returned
oraResults.Fields(0)>Value - Value from first record is returned
Try something like this: loop through the oraResults recordset and read the records:
Do until oraResults.EOF
Response.Write oraResults("firstFieldName")
Response.Write oraResults("secondFieldName")
oraResults.MoveNext
Loop
Here's a link that might help.

Resources