Baljeet Singh

Your Technical Guide

Writing Data in Excel VB.net

clock May 9, 2012 13:38 by author Administrator

Step 1: Add Reference-> COM->Microsoft Excel 12 Library

Step 2:

    Dim xlApp As Microsoft.Office.Interop.Excel.Application

    Dim xlBook As Microsoft.Office.Interop.Excel.Workbook

    Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
    Public Sub WriteExcel()
        xlApp = CType(CreateObject("Excel.Application"), Microsoft.Office.Interop.Excel.Application)

        xlBook = CType(GetObject("c:\book3.xls"), Microsoft.Office.Interop.Excel.Workbook)

        xlSheet = CType(xlBook.Worksheets("Sheet1"), Microsoft.Office.Interop.Excel.Worksheet)

        ' Show the sheet. 

        xlSheet.Activate()

        xlSheet.Visible = Microsoft.Office.Interop.Excel.XlSheetVisibility.xlSheetVisible


        'Enter Data
        xlSheet.Cells(4, 2) = "test"
        xlSheet.Cells(4, 3) = "Dummy"

        xlBook.Save()

        xlBook.Close()

        'xlApp.Quit to close the work sheet. 

        xlApp.Quit()

    End Sub



Paypal PDT verification

clock May 8, 2012 15:44 by author Administrator

Use the following function for verification

Function PostToPayPal(ByVal sTX As String) As String
            Dim tx, PDTvalidateQuery, token As String
            Dim strResponse As HttpWebResponse
            Dim temp As String
            'Dim PDTArray() As String
            Dim iParts, sResults(0, 0), aParts(), sParts(), sKey, sValue As String
            Dim i As Integer
            Dim firstname, lastName, itemName, mcGross, mcCurrency As String
 
            'production WRF token
            token = "1jGOL41IoO4KqBBdl51borXO8eavZoYzyIFcd0H69c1ZShsxK6JD0fZDm5i"
 
            'test token
            'token = "pAsF96B7LJPK2k4fsa-oHQR-tyQl-Bu9gKxi7DH72svl3K-UbT0ETGVCJqS"
 
            tx = sTX
 
            'set string = to the cmd value, tx and at that needs to be POSTed back to PayPal to validate the PDT
            PDTvalidateQuery = "cmd=_notify-synch&tx=" & tx & "at=" & token
 
            'Now we need to POST this info back to PayPal for validation of the PDT. Create the request back:
            Dim req As HttpWebRequest = CType(WebRequest.Create("https://www.paypal.com/cgi-bin/webscr"), HttpWebRequest)
            'Dim req As HttpWebRequest = CType(WebRequest.Create("https://www.sandbox.paypal.com/cgi-bin/webscr"), HttpWebRequest)
 
            ' Set values for the request back
            req.Method = "POST"  'set method
            req.ContentType = "application/x-www-form-urlencoded"
            req.ContentLength = PDTvalidateQuery.Length
 
            ' Write the request back to PayPal
            Dim stOut As StreamWriter = New StreamWriter(req.GetRequestStream(), Encoding.ASCII)
            stOut.Write(PDTvalidateQuery)
            stOut.Close()
 
            Try
                strResponse = CType(req.GetResponse(), HttpWebResponse)
            Catch ex As SystemException
                LogError(ex)
            End Try
 
            'Once we write the stream back to PayPal, we need to read the
            'response.
            Dim IPNResponseStream As Stream = strResponse.GetResponseStream
            Dim encode As Encoding = System.Text.Encoding.GetEncoding("utf-8")
            Dim readStream As New StreamReader(IPNResponseStream, encode)
 
            'read the response intoa String variable "temp"
            temp = readStream.ReadToEnd
 
            'Check to see if the 1st line of the response was "SUCCESS"
            Dim strOutput As String
            If Mid(temp, 1, 7) = "SUCCESS" Then
 
                'if it is SUCCESS, the code below puts the
                'response in a nice array
                temp = Mid(temp, 9)
                sParts = Split(temp, vbLf)
                iParts = UBound(sParts) - 1
                ReDim sResults(iParts, 1)
 
                For i = 0 To iParts
                    aParts = Split(sParts(i), "=")
                    sKey = aParts(0)
                    sValue = aParts(1)
                    sResults(i, 0) = sKey
                    sResults(i, 1) = sValue
                    'add more case statements here in order to access other returned variables
                    Select Case sKey
                        Case "first_name"
                            firstname = sValue
                        Case "last_name"
                            lastName = sValue
                        Case "item_name"
                            itemName = sValue
                        Case "mc_gross"
                            mcGross = sValue
                        Case "mc_currency"
                            mcCurrency = sValue
                    End Select
                Next
                strOutput = "<h2><b>Thanks for your Order!!</b></h2><br><br>"
                strOutput += "<li>Name: " & firstname & " " & lastName & "</li>"
                strOutput += "<li>Description: " & itemName & "</li>"
                strOutput += "<li>Amount: " & mcCurrency & " " & mcGross & "</li>"
                'debug
                'OutputEntirePDTString(temp)
            Else
                ' IF PDT response is "FAIL" - investigate
                strOutput = "Error - PDT FAIL"
            End If
 
            'close opened streams
            readStream.Close()
            strResponse.Close()
            PostToPayPal = strOutput
        End Function


Paypal PDT, Fail Error: 4020

clock May 8, 2012 15:39 by author Administrator

When you attempt to verify PDT transaction data by posting a _notify-synch command.  However, in 9 times out of 10 the cause is due to the request containing an incorrect ‘at’ or authorisation token argument.

 The ‘authorisation token’, or ‘Identity Token’ is a big long alphanumeric string, to find yours log into your paypal account, click on ‘Profile’, then click on ‘Website Payment Preferences’, scroll down to the ‘Payment Data Transfer’ section – you will see your ‘Identity Token’ at the end of this section.

 This token must be included in your _notify-synch command as an argument named ‘at’.



Insert an Identity Column using Queries

clock May 7, 2012 15:09 by author Administrator
Alter Table Names
Add Id_new Int Identity(1, 1)


Could not determine a MetaTable. A MetaTable could not be determined for the data source 'SqlDataSource1' and one could not be inferred from the request URL. Make sure that the table is mapped to the dats source, or that the data source is configured with a valid context type and table name, or that the request is part of a registered DynamicDataRoute.

clock May 5, 2012 13:07 by author Administrator

It is due to the fact you might have used DynamicField in GridView

To be able to use Dynamic Data you need to add a Data Model to your project, either in the form of LINQ to SQL or an Entity Framework data model.

changing columns from something like so:

<Columns>
 
<asp:DynamicField DataField="Id" HeaderText="Id" />
</Columns>

to this:

<Columns>
 
<asp:BoundField DataField="Id" HeaderText="Id" />
</Columns>



About Guide

I have been in teaching for around 10 years, and into the development for around 4 years, impart training to students has given me the best exposure in this field. I have worked with National as well as International Clients.

Calendar

<<  May 2012  >>
MoTuWeThFrSaSu
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

View posts in large calendar

RecentComments

Comment RSS

Sign in