Showing posts with label create. Show all posts
Showing posts with label create. Show all posts

Thursday, March 29, 2012

Pass Recordset from Web Service to Classic ASP.

I want to use the .net Web Service to create a function and return the
datas (RecordSet). And want to retrived those data on the classic ASP.
Does any body have some example of this. How to create the Recordset in
webservice and get it at classic asp.
Thanks and Regards.Ted Ngo wrote:
> I want to use the .net Web Service to create a function and return the
> datas (RecordSet). And want to retrived those data on the classic ASP.
> Does any body have some example of this. How to create the Recordset
> in webservice and get it at classic asp.
> Thanks and Regards.
See this thread:
http://groups.google.com/group/micr...29ded2e3b036cec
Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
so I using this
Or, you can send the XML of the ADO recordset back, and re-construct it
on
the client. Use Interop on the server to work with the ADO recordset.
// ON THE SERVER -- Web Service
// Add references to ADODB library
// Create a stream object
myStream = new ADODB.Stream();
// Replace the constants with their actual values
recordSet.Save(myStream, adPersistXML);
output = myStream.ReadText(adReadAll);
// Return the XML string, complete with schema
return output;
To return the recorset
and then on the asp using this to get the record set
Public Function RecordsetFromXMLString(sXML As String) As Recordset
Dim oStream As ADODB.Stream
Set oStream = New ADODB.Stream
oStream.Open
oStream.WriteText sXML 'Give the XML string to the ADO Stream
oStream.Position = 0 'Set the stream position to the start
Dim oRecordset As ADODB.Recordset
Set oRecordset = New ADODB.Recordset
oRecordset.Open oStream 'Open a recordset from the stream
oStream.Close
Set oStream = Nothing
Set RecordsetFromXMLString = oRecordset 'Return the recordset
Set oRecordset = Nothing
End Function
Is that righ?
Thanks
Yes, that's what I had in mind. Also, see Adam's last message in that
thread.
Bob
Ted Ngo wrote:
> so I using this
> Or, you can send the XML of the ADO recordset back, and re-construct
> it on
> the client. Use Interop on the server to work with the ADO recordset.
>
> // ON THE SERVER -- Web Service
> // Add references to ADODB library
>
> // Create a stream object
> myStream = new ADODB.Stream();
>
> // Replace the constants with their actual values
> recordSet.Save(myStream, adPersistXML);
> output = myStream.ReadText(adReadAll);
>
> // Return the XML string, complete with schema
> return output;
> To return the recorset
> and then on the asp using this to get the record set
> Public Function RecordsetFromXMLString(sXML As String) As Recordset
> Dim oStream As ADODB.Stream
> Set oStream = New ADODB.Stream
> oStream.Open
> oStream.WriteText sXML 'Give the XML string to the ADO Stream
> oStream.Position = 0 'Set the stream position to the start
> Dim oRecordset As ADODB.Recordset
> Set oRecordset = New ADODB.Recordset
> oRecordset.Open oStream 'Open a recordset from the stream
> oStream.Close
> Set oStream = Nothing
> Set RecordsetFromXMLString = oRecordset 'Return the recordset
> Set oRecordset = Nothing
> End Function
> Is that righ?
> Thanks
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

Monday, March 26, 2012

Pass Values to another page.

I am trying to a create a page that will query a SQLDB get customer
information and then pass this information on to another page creating
almost like a mail merge letter. I can get the information no problem using
a repeater but how do I pass <%#container.DataItem("Value1")%> to another
page.

Thx.Hi

Put information you want to share between pages either in
Session Object or Cache Object.

Ravikanth

>--Original Message--
>I am trying to a create a page that will query a SQLDB
get customer
>information and then pass this information on to another
page creating
>almost like a mail merge letter. I can get the
information no problem using
>a repeater but how do I pass <%#container.DataItem
("Value1")%> to another
>page.
>Thx.
>
>.
Can u give me an example of this?

"Ravikanth[MVP]" <dvravikanth@.hotmail.com> wrote in message
news:015f01c351fa$14740ed0$a101280a@.phx.gbl...
> Hi
> Put information you want to share between pages either in
> Session Object or Cache Object.
> Ravikanth
>
> >--Original Message--
> >I am trying to a create a page that will query a SQLDB
> get customer
> >information and then pass this information on to another
> page creating
> >almost like a mail merge letter. I can get the
> information no problem using
> >a repeater but how do I pass <%#container.DataItem
> ("Value1")%> to another
> >page.
> >Thx.
> >.

Saturday, March 24, 2012

Pass variable between sub routines

Hi,

I'm trying to write some code that will create an order number by searching through an order_detail table for the highest numbered order number. Once found, I would like to pass this number to the FillOrder sub routine, which inserts it into the order_detail table. It looks like the findMax routine works, since the response.write statement a the end of it prints out the correct number. However, the response.write statements in the fillorder routine do not display, nor does the table get populated. I think the first problem is that I may not be passing the "highest" variable correctly.

I know the code is probably hack, but I would appreciate help/advice.

Thanks in advance.

Tom


Public Sub findMax()
Dim highest As Int32
Dim strMax As String
Const strMaxConn As String = "data source=ENVISAGENT1;initial catalog=tsproductsSQL3;integrated security=SSPI;persist security info=False;workstation id=ENVISAGENT1;packet size=4096"
Dim objMaxConn As New SqlConnection(strMaxConn)
Dim dsOrderHead As DataSet
Dim daOrderHead As SqlDataAdapter
dsOrderHead = New DataSet()

strMax = "SELECT MAX(order_num) as highest FROM order_header"
Dim CmdMax As New SqlCommand(strMax, objMaxConn)

If numOrders = 0 Then
highest = numOrders + 1
End If

If numOrders > 0 Then
objMaxConn.Open() 'open connection

'run SQL command
CmdMax.ExecuteNonQuery()

objMaxConn.Close() 'close connection
End If
Response.Write(highest)
FillOrder(highest)
End Sub

'populate order_detail table
Public Sub FillOrder(ByVal ordNum As Int32)
'findMax()

Const strFillOrdConn As String = "data source=ENVISAGENT1;initial catalog=tsproductsSQL3;integrated security=SSPI;persist security info=False;workstation id=ENVISAGENT1;packet size=4096"
Dim objFillOrdConn As New SqlConnection(strFillOrdConn)
Dim daFillOrd As SqlDataAdapter
Dim strFillOrdSQL As String

Dim detNum As Int32 = 0
Response.Write("DetailNum " & detNum)
Response.Write("PRoduct " & grdCart.Items(1).Cells(1).Text)

strFillOrdSQL = "INSERT order_num,detail_num,product_num,quantity,line_item_price INTO order_detail values (ordNum,detNum,pnum,quan,price)"

Dim CmdFillOrd As New SqlCommand(strFillOrdSQL, objFillOrdConn)

objFillOrdConn.Open()

' Iterate through all rows within shopping cart list
Dim i As Integer

For i = 0 To grdCart.Items.Count - 1
'for each item in cart,
'insert current order #, detail#,product, quantity & price
'into order_detail

detNum = detNum + 1

Dim pnum As Int32 = Convert.ToInt32(grdCart.Items(i).Cells(1).Text)
Dim price As Decimal = Convert.ToDecimal(grdCart.Items(i).Cells(3).Text)
Dim quan As Int32 = Convert.ToInt32(grdCart.Items(i).Cells(4).Text)

CmdFillOrd.ExecuteNonQuery()

Next

objFillOrdConn.Close()

Hi Tom,
There is no embeded variables in ADO.NET. You have to create command with parameters and use them. Alter your code this way (check types of parameters):

' ...
strFillOrdSQL = "INSERT order_num,detail_num,product_num,quantity,line_item_price INTO order_detail values (@.ordNum,@.detNum,@.pnum,@.quan,@.price)"

Dim CmdFillOrd As New SqlCommand(strFillOrdSQL, objFillOrdConn)
CmdFillOrd.Parameters.Add(New SqlParameter("@.ordNum", SqlDbType.Int))
CmdFillOrd.Parameters.Add(New SqlParameter("@.detNum", SqlDbType.Int))
CmdFillOrd.Parameters.Add(New SqlParameter("@.pnum", SqlDbType.Int))
CmdFillOrd.Parameters.Add(New SqlParameter("@.quan", SqlDbType.Int))
CmdFillOrd.Parameters.Add(New SqlParameter("@.price", SqlDbType.Decimal))

CmdFillOrd.Parameters[0].Value = ordNum
objFillOrdConn.Open()

' Iterate through all rows within shopping cart list
Dim i As Integer

For i = 0 To grdCart.Items.Count - 1
'for each item in cart,
'insert current order #, detail#,product, quantity & price
'into order_detail

detNum = detNum + 1
CmdFillOrd.Parameters[1].Value = detNum

Dim pnum As Int32 = Convert.ToInt32(grdCart.Items(i).Cells(1).Text)
Dim price As Decimal = Convert.ToDecimal(grdCart.Items(i).Cells(3).Text)
Dim quan As Int32 = Convert.ToInt32(grdCart.Items(i).Cells(4).Text)

CmdFillOrd.Parameters[2].Value = pnum
CmdFillOrd.Parameters[3].Value = quan
CmdFillOrd.Parameters[4].Value = price

CmdFillOrd.ExecuteNonQuery()
Next


Thank-you. I'll give it a try.
Ok I finally got around to trying the code - it looks like it may work, but again, nothing happens after the findMax sub routine listed above. It is as if it isn't even invoking. Also, I took the response.write("Highest = " & highest) statement out, and it still displays the text when the button is clicked. Why does this persist even though the statement is out? Does it also have something to do with the FillOrder sub routing apparantly doing nothing?

Thanks

Tom
There are only two possible explanations for persisting results of response.write:
1. Page is cached and not executed at all
2. You are running wrong version of page
How would I determine which one? I've tried deleting cache files to no avail.
Try to change something visual on page (add some text for example) and see if you receive changes when page is served.
I did all of that.

If you look at the connection strings in the code above, are they creating a cache that persists?

I created new pages and copied the code over to them. I changed the connection strings to "server=localhost;database=tsproductssql3;uid=sa;pwd=sa" and ran it. I got rid of the persistent response.write, and was able to display all of the others. However, I tried again, and got a database (primary key) violation which I have to sort out to see if the problems persist. I'll re-post then.

Thanks for your replies.

Tom
OK, cleared up the persist problem.

If you (or someone) could tell me if the original connection string (above) that I had would have created this cache & persist problem, that would be great. I'm still getting a lot of roadrash fumbling my way through my first ASP.NET project.

Thanks

Tom

passing a collection to a function

What I am doing is creating a web based email, using .net

I have finised the inbox, read, delete email etc..

Im in the process of making the "create email" or compose...

What the plan is, for people to be able to enter multiple "To:" "CC:" and "BCC:"

I have only done the "To:" field as yes, Atrax gave me the hint on how to split the emails with a ";" using split

What that did thou was place the emails into an array, which made it a pain to remove any blank emails which would cause an error...
I would always be working with strings, Below is the code that works with the "To" field

Dim arrTo(), strEmail As String
Dim j, intColCount, intEmptyColID As Integer
Dim colTo As ArrayList
Dim bolValidEmails, bolFoundInvalid As Boolean
'Dim objMsg As Object
'objMsg = Server.CreateOBject("JMail.Message")
'objMsg.Logging = true
'objMsg.Silent = true
'objMsg.From = Session("EmailAddress")
'\\\\\\\\\\\\\\\Splits the "To:" information into different emails - placing them into a collection for later use
colTo = New ArrayList
arrTo = strTo.Split(";")
For Each strEmail in arrTo
colTo.Add(trim(strEmail))
Next
'\\\\\\\\\\\\\\\Erases any empty emails out of the collection
bolValidEmails = False
bolFoundInvalid = False
intEmptyColID = -1
Do While bolValidEmails = False
For j = 0 To colTo.Count - 1
If bolFoundInvalid = False Then
If colTo(j) = "" Then
bolFoundInvalid = True
intEmptyColID = j
End If
End If
Next
If bolFoundInvalid = True Then
bolValidEmails = False
colTo.RemoveAt(intEmptyColID)
Else
bolValidEmails = True
End If
intEmptyColID = -1
bolFoundInvalid = False
Loop
'\\\\\\\\\\\\\\\Trims the Collection
colTo.TrimToSize()

What I want to do is, after I create the collection for any of the "to" "cc" and "bcc" is call that function and empty any blank emails, but I dont know how to pass the collection to the function and return the collection and continue on...

I was only using the
Dim strRandom As String
Dim objRand As New Misc
strRandom = objRand.GenerateRandNum()
objRand = Nothing
Response.Redirect("inbox.aspx?rnd=" & strRandom)

as an example of what i wanted to do as i couldn't remember the name after so many hours of programming =)...

I was asking can i use something like

Dim objChecker As New Misc
objRand.GenerateRandNum(ByRef collection name as ??)
objRand = Nothing
'continue with the rest of the email processing

do you have any code that passes a collection to a function like that? That I can look at, As I will need to be able to use the same function by multiple classes..(eg on the "reply", "Create email", "forward" class etc )

Thanks heaps

Hawk
ws abyss at infoyou can use a function with a parametere of collection as

1- dimension
private function myfunction(ByVal Arrto() As String)
or
private function myfunction(ByVal Arrto As String())

2- dimension
private function myfunction(ByVal Arrto(,) As String)
or
private function myfunction(ByVal Arrto As String(,))

Regards
Ather Ali Shaikh
"Hawk" <anonymous@.discussions.microsoft.com> wrote in message
news:13B899D4-3698-4E51-AC58-5FBE388D9C75@.microsoft.com...
> What I am doing is creating a web based email, using .net
> I have finised the inbox, read, delete email etc..
> Im in the process of making the "create email" or compose...
> What the plan is, for people to be able to enter multiple "To:" "CC:" and
"BCC:"
> I have only done the "To:" field as yes, Atrax gave me the hint on how to
split the emails with a ";" using split
> What that did thou was place the emails into an array, which made it a
pain to remove any blank emails which would cause an error...
> I would always be working with strings, Below is the code that works with
the "To" field
>
> Dim arrTo(), strEmail As String
> Dim j, intColCount, intEmptyColID As Integer
> Dim colTo As ArrayList
> Dim bolValidEmails, bolFoundInvalid As Boolean
> 'Dim objMsg As Object
> 'objMsg = Server.CreateOBject("JMail.Message")
> 'objMsg.Logging = true
> 'objMsg.Silent = true
> 'objMsg.From = Session("EmailAddress")
> '\\\\\\\\\\\\\\\Splits the "To:" information into different
emails - placing them into a collection for later use
> colTo = New ArrayList
> arrTo = strTo.Split(";")
> For Each strEmail in arrTo
> colTo.Add(trim(strEmail))
> Next
> '\\\\\\\\\\\\\\\Erases any empty emails out of the collection
> bolValidEmails = False
> bolFoundInvalid = False
> intEmptyColID = -1
> Do While bolValidEmails = False
> For j = 0 To colTo.Count - 1
> If bolFoundInvalid = False Then
> If colTo(j) = "" Then
> bolFoundInvalid = True
> intEmptyColID = j
> End If
> End If
> Next
> If bolFoundInvalid = True Then
> bolValidEmails = False
> colTo.RemoveAt(intEmptyColID)
> Else
> bolValidEmails = True
> End If
> intEmptyColID = -1
> bolFoundInvalid = False
> Loop
> '\\\\\\\\\\\\\\\Trims the Collection
> colTo.TrimToSize()
>
> What I want to do is, after I create the collection for any of the "to"
"cc" and "bcc" is call that function and empty any blank emails, but I dont
know how to pass the collection to the function and return the collection
and continue on...
> I was only using the
> Dim strRandom As String
> Dim objRand As New Misc
> strRandom = objRand.GenerateRandNum()
> objRand = Nothing
> Response.Redirect("inbox.aspx?rnd=" & strRandom)
> as an example of what i wanted to do as i couldn't remember the name after
so many hours of programming =)...
> I was asking can i use something like
> Dim objChecker As New Misc
> objRand.GenerateRandNum(ByRef collection name as ??)
> objRand = Nothing
> 'continue with the rest of the email processing
>
> do you have any code that passes a collection to a function like that?
That I can look at, As I will need to be able to use the same function by
multiple classes..(eg on the "reply", "Create email", "forward" class etc )
> Thanks heaps
> Hawk
> ws abyss at info

Wednesday, March 21, 2012

Passing a CSV file into APSX page and returning query from SQL server using CSV data?

Is this possible basically?

I have a CSV file that contains a list of barcodes, I would like to create a page that will upload this into a temp table of some kind and query a SQL using the CSV file to join the data to the table.

This would then output the result to a list on the page.


Any ideas? As yet I haven't managed to start anything on ASP.net yet!

Of course it's possible. Almost anything is possible. When you get to your coding you should ask the specific questions that you need answered.


Here is one way on how to do this

1. Read your file using FileStream.
2. Create a datatable and its columns.
3. Loop through your file (using FileStream) and populate your datatable.
4. Create a dataview and set to the datatable.
5. Use rowfilter to filter out data you don't want to show.
6. Bind the data to your DataGrid or DataList to display the data onto the page.


Many thanks for your reply, more the kinda reply that I was hoping for.

The method that you have said, trying to understand this:

Does part 3 put the data into the database?

Where do I execute a query/sp to get the correct additional data back? (As more relevant data will be coming back based on a join to the new fields in the table)?

Thanks

Passing a parameter to get results to post to a datagrid

I am beginning to go crazy! I am trying to create a form where someone picks from a DropDownList data from a column in a table, pass what they picked as a parameter for a SQL query. For example, the choose a "Reference Document" type from the dropdown list and I want to display all records = to the reference type selected. I am able to creat it only if I use "like" in my query for the parameter and not = which I need...please please help!

here is my code:

<%@dotnet.itags.org. Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<%@dotnet.itags.org. Register TagPrefix="MM" Namespace="DreamweaverCtrls" Assembly="DreamweaverCtrls,version=1.0.0.0,publicKeyToken=836f606ede05d46a,culture=neutral" %>
<MM:DataSet
id="DataSetResults"
runat="Server"
IsStoredProcedure="false"
ConnectionString='<%# System.Configuration.ConfigurationSettings.AppSettings("MM_CONNECTION_STRING_CPAR") %>'
DatabaseType='<%# System.Configuration.ConfigurationSettings.AppSettings("MM_CONNECTION_DATABASETYPE_CPAR") %>'
CommandText='<%# "SELECT * FROM dbo.ListofNonconformities WHERE ""Reference Document"" = ?" %>'
Debug="true" PageSize="10"
><Parameters>
<Parameter Name="@dotnet.itags.org.Reference Document" Value='<%# IIf((Request.Form("FRefDoc") <> Nothing), Request.Form("FRefDoc"), "") %>' Type="WChar" /></Parameters></MM:DataSet>
<MM:PageBind runat="server" PostBackBind="true" />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form action="" method="post" name="FRefDoc" id="FRefDoc" runat="server">
<p>
<% DDRefDoc.SelectedIndex = DDRefDoc.Items.IndexOf(DDRefDoc.Items.FindByValue(DataSetResults.FieldValue("Reference Document", Nothing) )) %><asp:DropDownList ID="DDRefDoc" runat="server" DataSource="<%# DataSetResults.DefaultView %>" DataTextField="Reference Document" DataValueField="Reference Document"></asp:DropDownList>
<asp:Button ID="BSubmit" runat="server" Text="Submit" /></p>
<p>
<asp:DataGrid id="DataGridResults"
runat="server"
AllowSorting="False"
AutoGenerateColumns="false"
CellPadding="3"
CellSpacing="0"
ShowFooter="false"
ShowHeader="true"
DataSource="<%# DataSetResults.DefaultView %>"
PagerStyle-Mode="NextPrev"
AllowPaging="true"
AllowCustomPaging="true"
PageSize="<%# DataSetResults.PageSize %>"
VirtualItemCount="<%# DataSetResults.RecordCount %>"
OnPageIndexChanged="DataSetResults.OnDataGridPageIndexChanged"
>
<HeaderStyle HorizontalAlign="center" BackColor="#E8EBFD" ForeColor="#3D3DB6" Font-Name="Verdana, Arial, Helvetica, sans-serif" Font-Bold="true" Font-Size="smaller" />
<ItemStyle BackColor="#F2F2F2" Font-Name="Verdana, Arial, Helvetica, sans-serif" Font-Size="smaller" />
<AlternatingItemStyle BackColor="#E5E5E5" Font-Name="Verdana, Arial, Helvetica, sans-serif" Font-Size="smaller" />
<FooterStyle HorizontalAlign="center" BackColor="#E8EBFD" ForeColor="#3D3DB6" Font-Name="Verdana, Arial, Helvetica, sans-serif" Font-Bold="true" Font-Size="smaller" />
<PagerStyle BackColor="white" Font-Name="Verdana, Arial, Helvetica, sans-serif" Font-Size="smaller" />
<Columns>
<asp:BoundColumn DataField="ISO 9001 Clause"
HeaderText="ISO 9001 Clause"
ReadOnly="true"
Visible="True"/>
<asp:BoundColumn DataField="Expr1"
HeaderText="Expr1"
ReadOnly="true"
Visible="True"/>
<asp:BoundColumn DataField="Action To:"
HeaderText="Action To:"
ReadOnly="true"
Visible="True"/>
<asp:BoundColumn DataField="Description of Nonconformity"
HeaderText="Description of Nonconformity"
ReadOnly="true"
Visible="True"/>
<asp:BoundColumn DataField="Verified By"
HeaderText="Verified By"
ReadOnly="true"
Visible="True"/>
<asp:BoundColumn DataField="Submission Date"
HeaderText="Submission Date"
ReadOnly="true"
Visible="True"/>
<asp:BoundColumn DataField="Completion Date"
HeaderText="Completion Date"
ReadOnly="true"
Visible="True"/>
<asp:BoundColumn DataField="Verification Date"
HeaderText="Verification Date"
ReadOnly="true"
Visible="True"/>
<asp:BoundColumn DataField="Reference Document"
HeaderText="Reference Document"
ReadOnly="true"
Visible="True"/>
<asp:BoundColumn DataField="Process Owner"
HeaderText="Process Owner"
ReadOnly="true"
Visible="True"/>
<asp:BoundColumn DataField="Remarks"
HeaderText="Remarks"
ReadOnly="true"
Visible="True"/>
</Columns>
</asp:DataGrid>
</p>
<p> </p>
</form>
</body>
</html>that is very good
thank you

Friday, March 16, 2012

Passing an array as a session variable

I have 2 asp.net forms. In the first form I create a one dimensional array and copy that array into a session object. In the second form I want to read the elements of that array. Everything I've tried results in either a casting error, a late binding error or nothing at all. The following code shows what Iwant to do.

Form one: Dim aArray(2) as stringaArray(0) = "zero"aArray(1) = "one"Session("PassArray") = aArray
Form two: Dim aTest(2) as stringaTest(0) = CType(Session("PassArray(0)"), String)aTest(1) = CType(Session("PassArray(1)"), String)When I run form two in the editor, I can Watch Session("PassArray") and see:Session("PassArray") {System.Array} object-- (0) "zero" string-- (1) "one" stringSo I know it's there and available, but how do I read the extents.

Could really use a simple code example to explain what I'm doing wrong.

Hi,

Use this on the second form:

Dim aTest() As String = CType(Session("PassArray"), String())


That did it. Thank you.