trevoray
asked on
credit card processing and returned ASCII value
hey, i am converting my old asp classic form to .NET and dealing with the whole credit card processing for the first time via .NET. i have got it all working now and my data is returned back from me from the credit card processor in a POST stream.
the only problem is that the data is returned back in ASCII format with no commas or quotation marks. it looks just like this:
ssl_result=0 ssl_result_message=APPROVE D ssl_txn_id=00000000-0000-0 000-0000-0 0000000000 0 ssl_approval_code=123456 ssl_cvv2_response=P ssl_avs_response=X ssl_transaction_type=SALE ssl_amount=53
how can i parse this without commas so that i can populate my SQL Server database?
the only problem is that the data is returned back in ASCII format with no commas or quotation marks. it looks just like this:
ssl_result=0 ssl_result_message=APPROVE
how can i parse this without commas so that i can populate my SQL Server database?
ASKER
and for some reason, when i display the results in a textbox, it knows when to do a return after each entry, so that the textbox looks like this:
ssl_result=0
ssl_result_message=APPROVE D
ssl_txn_id=00000000-0000-0 000-0000-0 0000000000 0
ssl_approval_code=123456
ssl_cvv2_response=P
ssl_avs_response=X
ssl_transaction_type=SALE
ssl_amount=53
ssl_result=0
ssl_result_message=APPROVE
ssl_txn_id=00000000-0000-0
ssl_approval_code=123456
ssl_cvv2_response=P
ssl_avs_response=X
ssl_transaction_type=SALE
ssl_amount=53
how about this ... real working example!!
Imports System.Text.RegularExpress ions
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.ICon tainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Butto n
Friend WithEvents TextBox1 As System.Windows.Forms.TextB ox
Friend WithEvents ListView1 As System.Windows.Forms.ListV iew
<System.Diagnostics.Debugg erStepThro ugh()> Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Butto n
Me.TextBox1 = New System.Windows.Forms.TextB ox
Me.ListView1 = New System.Windows.Forms.ListV iew
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(296, 16)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(152, 88)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Continue"
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(8, 16)
Me.TextBox1.Multiline = True
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(264, 72)
Me.TextBox1.TabIndex = 1
Me.TextBox1.Text = "ssl_result=0 ssl_result_message=APPROVE D ssl_txn_id=00000000-0000-0 000-0000-0 0000" & _
"0000000 ssl_approval_code=123456 ssl_cvv2_response=P ssl_avs_response=X ssl_tran" & _
"saction_type=SALE ssl_amount=53 "
'
'ListView1
'
Me.ListView1.AllowColumnRe order = True
Me.ListView1.FullRowSelect = True
Me.ListView1.GridLines = True
Me.ListView1.HoverSelectio n = True
Me.ListView1.Location = New System.Drawing.Point(16, 136)
Me.ListView1.Name = "ListView1"
Me.ListView1.Size = New System.Drawing.Size(400, 136)
Me.ListView1.TabIndex = 2
Me.ListView1.View = System.Windows.Forms.View. Details
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(472, 302)
Me.Controls.Add(Me.ListVie w1)
Me.Controls.Add(Me.TextBox 1)
Me.Controls.Add(Me.Button1 )
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim rx As New Regex("(?<ssl_result>ssl_r esult) = (?<ssl_result_Value> .*)\s (?<ssl_result_message>ssl_ result_mes sage) = (?<ssl_result_message_Valu e> .*)\s (?<ssl_txn_id>ssl_txn_id) = (?<ssl_txn_id_Value> .* )\s (?<ssl_approval_code>ssl_a pproval_co de) = (?<ssl_approval_code_Value > .* )\s (?<ssl_cvv2_response>ssl_c vv2_respon se) = (?<ssl_cvv2_response_Value > .* )\s (?<ssl_avs_response>ssl_av s_response ) = (?<ssl_avs_response_Value> .* )\s (?<ssl_transaction_type>ss l_transact ion_type) = (?<ssl_transaction_type_Va lue> .* )\s (?<ssl_amount>ssl_amount) = (?<ssl_amount_Value> .* )\s", RegexOptions.IgnoreCase Or RegexOptions.Multiline Or RegexOptions.IgnorePattern Whitespace Or RegexOptions.Compiled)
Dim match As Match = rx.Match(Me.TextBox1.Text)
If match.Groups.Count Mod 2 = 0 Then
MessageBox.Show("Missing parameters")
Else
Me.ListView1.Columns.Add(" Parameter" , Me.ListView1.Width / 2, HorizontalAlignment.Center )
Me.ListView1.Columns.Add(" Value", Me.ListView1.Width / 2, HorizontalAlignment.Center )
Dim gp As Group
Dim x As Short = (match.Groups.Count / 2)
Dim y As Short
For y = 1 To x
With Me.ListView1.Items.Add(mat ch.Groups( y * 2 - 1).Value)
.SubItems.Add(match.Groups (y * 2).Value)
End With
Next
End If
End Sub
End Class
Imports System.Text.RegularExpress
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.ICon
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Butto
Friend WithEvents TextBox1 As System.Windows.Forms.TextB
Friend WithEvents ListView1 As System.Windows.Forms.ListV
<System.Diagnostics.Debugg
Me.Button1 = New System.Windows.Forms.Butto
Me.TextBox1 = New System.Windows.Forms.TextB
Me.ListView1 = New System.Windows.Forms.ListV
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(296, 16)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(152, 88)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Continue"
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(8, 16)
Me.TextBox1.Multiline = True
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(264, 72)
Me.TextBox1.TabIndex = 1
Me.TextBox1.Text = "ssl_result=0 ssl_result_message=APPROVE
"0000000 ssl_approval_code=123456 ssl_cvv2_response=P ssl_avs_response=X ssl_tran" & _
"saction_type=SALE ssl_amount=53 "
'
'ListView1
'
Me.ListView1.AllowColumnRe
Me.ListView1.FullRowSelect
Me.ListView1.GridLines = True
Me.ListView1.HoverSelectio
Me.ListView1.Location = New System.Drawing.Point(16, 136)
Me.ListView1.Name = "ListView1"
Me.ListView1.Size = New System.Drawing.Size(400, 136)
Me.ListView1.TabIndex = 2
Me.ListView1.View = System.Windows.Forms.View.
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(472, 302)
Me.Controls.Add(Me.ListVie
Me.Controls.Add(Me.TextBox
Me.Controls.Add(Me.Button1
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim rx As New Regex("(?<ssl_result>ssl_r
Dim match As Match = rx.Match(Me.TextBox1.Text)
If match.Groups.Count Mod 2 = 0 Then
MessageBox.Show("Missing parameters")
Else
Me.ListView1.Columns.Add("
Me.ListView1.Columns.Add("
Dim gp As Group
Dim x As Short = (match.Groups.Count / 2)
Dim y As Short
For y = 1 To x
With Me.ListView1.Items.Add(mat
.SubItems.Add(match.Groups
End With
Next
End If
End Sub
End Class
Note:
(?<ssl_result>ssl_result) = (?<ssl_result_Value> .*)\s (?<ssl_result_message>ssl_ result_mes sage) = (?<ssl_result_message_Valu e> .*)\s (?<ssl_txn_id>ssl_txn_id) = (?<ssl_txn_id_Value> .* )\s (?<ssl_approval_code>ssl_a pproval_co de) = (?<ssl_approval_code_Value > .* )\s (?<ssl_cvv2_response>ssl_c vv2_respon se) = (?<ssl_cvv2_response_Value > .* )\s (?<ssl_avs_response>ssl_av s_response ) = (?<ssl_avs_response_Value> .* )\s (?<ssl_transaction_type>ss l_transact ion_type) = (?<ssl_transaction_type_Va lue> .* )\s (?<ssl_amount>ssl_amount) = (?<ssl_amount_Value> \d+ ) \s?
((?<ParamName> [a-zA-Z0-9_]+) = (?<ParamName_Value>[a-zA-Z 0-9_]+) \s*)*
will match additional parameters
eg. it'll match (anytherParameter1=value1 anytherParameter2=value2) from
ssl_result=abc ssl_result_message=NOT_APP ROVED ssl_txn_id=123-456-7890-12 3456 ssl_approval_code=99999999 99AAANNN!! ! ssl_cvv2_response=P ssl_avs_response=X ssl_transaction_type=SALE ssl_amount=5323 anytherParameter1=value1 anytherParameter2=value2
'just a little improvement
'------------------------- ----
Imports System.Text.RegularExpress ions
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.ICon tainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Butto n
Friend WithEvents TextBox1 As System.Windows.Forms.TextB ox
Friend WithEvents ListView1 As System.Windows.Forms.ListV iew
<System.Diagnostics.Debugg erStepThro ugh()> Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Butto n
Me.TextBox1 = New System.Windows.Forms.TextB ox
Me.ListView1 = New System.Windows.Forms.ListV iew
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Anchor = CType((System.Windows.Form s.AnchorSt yles.Top Or System.Windows.Forms.Ancho rStyles.Ri ght), System.Windows.Forms.Ancho rStyles)
Me.Button1.Location = New System.Drawing.Point(352, 8)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(112, 72)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Parse ..."
'
'TextBox1
'
Me.TextBox1.Anchor = CType(((System.Windows.For ms.AnchorS tyles.Top Or System.Windows.Forms.Ancho rStyles.Le ft) _
Or System.Windows.Forms.Ancho rStyles.Ri ght), System.Windows.Forms.Ancho rStyles)
Me.TextBox1.Location = New System.Drawing.Point(8, 8)
Me.TextBox1.Multiline = True
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.ScrollBars = System.Windows.Forms.Scrol lBars.Vert ical
Me.TextBox1.Size = New System.Drawing.Size(336, 72)
Me.TextBox1.TabIndex = 1
Me.TextBox1.Text = "ssl_result=abc ssl_result_message=NOT_APP ROVED ssl_txn_id=123-456-7890-12 3456 ssl" & _
"_approval_code=9999999999 AAANNN!!! ssl_cvv2_response=P ssl_avs_response=X ssl_tr" & _
"ansaction_type=SALE ssl_amount=5323"
'
'ListView1
'
Me.ListView1.AllowColumnRe order = True
Me.ListView1.Anchor = CType((((System.Windows.Fo rms.Anchor Styles.Top Or System.Windows.Forms.Ancho rStyles.Bo ttom) _
Or System.Windows.Forms.Ancho rStyles.Le ft) _
Or System.Windows.Forms.Ancho rStyles.Ri ght), System.Windows.Forms.Ancho rStyles)
Me.ListView1.FullRowSelect = True
Me.ListView1.GridLines = True
Me.ListView1.HoverSelectio n = True
Me.ListView1.Location = New System.Drawing.Point(8, 88)
Me.ListView1.Name = "ListView1"
Me.ListView1.Size = New System.Drawing.Size(456, 208)
Me.ListView1.TabIndex = 2
Me.ListView1.View = System.Windows.Forms.View. Details
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(472, 302)
Me.Controls.Add(Me.ListVie w1)
Me.Controls.Add(Me.Button1 )
Me.Controls.Add(Me.TextBox 1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim rx As New Regex("(?<ssl_result>ssl_r esult) = (?<ssl_result_Value> .*)\s (?<ssl_result_message>ssl_ result_mes sage) = (?<ssl_result_message_Valu e> .*)\s (?<ssl_txn_id>ssl_txn_id) = (?<ssl_txn_id_Value> .* )\s (?<ssl_approval_code>ssl_a pproval_co de) = (?<ssl_approval_code_Value > .* )\s (?<ssl_cvv2_response>ssl_c vv2_respon se) = (?<ssl_cvv2_response_Value > .* )\s (?<ssl_avs_response>ssl_av s_response ) = (?<ssl_avs_response_Value> .* )\s (?<ssl_transaction_type>ss l_transact ion_type) = (?<ssl_transaction_type_Va lue> .* )\s (?<ssl_amount>ssl_amount) = (?<ssl_amount_Value> .* )", RegexOptions.IgnoreCase Or RegexOptions.Multiline Or RegexOptions.IgnorePattern Whitespace Or RegexOptions.Compiled)
'Dim rx As New Regex("(?<ssl_result>ssl_r esult) = (?<ssl_result_Value> .*)\s (?<ssl_result_message>ssl_ result_mes sage) = (?<ssl_result_message_Valu e> .*)\s (?<ssl_txn_id>ssl_txn_id) = (?<ssl_txn_id_Value> .* )\s (?<ssl_approval_code>ssl_a pproval_co de) = (?<ssl_approval_code_Value > .* )\s (?<ssl_cvv2_response>ssl_c vv2_respon se) = (?<ssl_cvv2_response_Value > .* )\s (?<ssl_avs_response>ssl_av s_response ) = (?<ssl_avs_response_Value> .* )\s (?<ssl_transaction_type>ss l_transact ion_type) = (?<ssl_transaction_type_Va lue> .* )\s (?<ssl_amount>ssl_amount) = (?<ssl_amount_Value> \d+ ) \s?((?<ParamName> [a-zA-Z0-9_]+) = (?<ParamName_Value>[a-zA-Z 0-9_]+) \s*)*", _
' RegexOptions.IgnoreCase Or RegexOptions.Multiline Or RegexOptions.IgnorePattern Whitespace Or RegexOptions.Compiled)
Dim match As Match = rx.Match(Me.TextBox1.Text)
Me.ListView1.Columns.Clear ()
Me.ListView1.Items.Clear()
If False Then ' match.Groups.Count Mod 2 = 0 Then
MessageBox.Show("Missing parameters")
Else
Me.ListView1.Columns.Add(" Parameter" , Me.ListView1.Width / 2, HorizontalAlignment.Center )
Me.ListView1.Columns.Add(" Value", Me.ListView1.Width / 2, HorizontalAlignment.Center )
Dim gp As Group
Dim x As Short = (match.Groups.Count / 2)
Dim y As Short
For y = 1 To x
With Me.ListView1.Items.Add(mat ch.Groups( y * 2 - 1).Value)
.SubItems.Add(match.Groups (y * 2).Value)
End With
Next
End If
End Sub
End Class
(?<ssl_result>ssl_result) = (?<ssl_result_Value> .*)\s (?<ssl_result_message>ssl_
((?<ParamName> [a-zA-Z0-9_]+) = (?<ParamName_Value>[a-zA-Z
will match additional parameters
eg. it'll match (anytherParameter1=value1 anytherParameter2=value2) from
ssl_result=abc ssl_result_message=NOT_APP
'just a little improvement
'-------------------------
Imports System.Text.RegularExpress
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.ICon
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Butto
Friend WithEvents TextBox1 As System.Windows.Forms.TextB
Friend WithEvents ListView1 As System.Windows.Forms.ListV
<System.Diagnostics.Debugg
Me.Button1 = New System.Windows.Forms.Butto
Me.TextBox1 = New System.Windows.Forms.TextB
Me.ListView1 = New System.Windows.Forms.ListV
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Anchor = CType((System.Windows.Form
Me.Button1.Location = New System.Drawing.Point(352, 8)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(112, 72)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Parse ..."
'
'TextBox1
'
Me.TextBox1.Anchor = CType(((System.Windows.For
Or System.Windows.Forms.Ancho
Me.TextBox1.Location = New System.Drawing.Point(8, 8)
Me.TextBox1.Multiline = True
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.ScrollBars = System.Windows.Forms.Scrol
Me.TextBox1.Size = New System.Drawing.Size(336, 72)
Me.TextBox1.TabIndex = 1
Me.TextBox1.Text = "ssl_result=abc ssl_result_message=NOT_APP
"_approval_code=9999999999
"ansaction_type=SALE ssl_amount=5323"
'
'ListView1
'
Me.ListView1.AllowColumnRe
Me.ListView1.Anchor = CType((((System.Windows.Fo
Or System.Windows.Forms.Ancho
Or System.Windows.Forms.Ancho
Me.ListView1.FullRowSelect
Me.ListView1.GridLines = True
Me.ListView1.HoverSelectio
Me.ListView1.Location = New System.Drawing.Point(8, 88)
Me.ListView1.Name = "ListView1"
Me.ListView1.Size = New System.Drawing.Size(456, 208)
Me.ListView1.TabIndex = 2
Me.ListView1.View = System.Windows.Forms.View.
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(472, 302)
Me.Controls.Add(Me.ListVie
Me.Controls.Add(Me.Button1
Me.Controls.Add(Me.TextBox
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim rx As New Regex("(?<ssl_result>ssl_r
'Dim rx As New Regex("(?<ssl_result>ssl_r
' RegexOptions.IgnoreCase Or RegexOptions.Multiline Or RegexOptions.IgnorePattern
Dim match As Match = rx.Match(Me.TextBox1.Text)
Me.ListView1.Columns.Clear
Me.ListView1.Items.Clear()
If False Then ' match.Groups.Count Mod 2 = 0 Then
MessageBox.Show("Missing parameters")
Else
Me.ListView1.Columns.Add("
Me.ListView1.Columns.Add("
Dim gp As Group
Dim x As Short = (match.Groups.Count / 2)
Dim y As Short
For y = 1 To x
With Me.ListView1.Items.Add(mat
.SubItems.Add(match.Groups
End With
Next
End If
End Sub
End Class
ASKER
wow, overload!! i do not have enough resources to handle all of that! :)
thanks for the code.
ok, my data is returned back to me from the processor in a string variable. the main help i need is taking that string variable and parsing it, then putting it into my SQL Database. Can you show me how to do that with your code?
thanks!
thanks for the code.
ok, my data is returned back to me from the processor in a string variable. the main help i need is taking that string variable and parsing it, then putting it into my SQL Database. Can you show me how to do that with your code?
thanks!
do you know how to execute the SQL statement from your vb code? (e.g. establishing connection, creating adapters, sql command etc).. or do you also want me to write you a code that does the insertion as well as parsing.
if so, i'm gonna need the name of the table, and the names of the columns where you'd like this data to be inserted.
- malhar
if so, i'm gonna need the name of the table, and the names of the columns where you'd like this data to be inserted.
- malhar
below is the code that does both .. note it is for win forms ... so some of the things i've done are not supported in asp. forexample, messagebox or msgbox is not supported in asp. so you'll have to come up with your error handling technique. you'll also have to use YOUR connection string, and apprpriate column names before you can use the functions. the acutal function is: Button2_Click. the code inside Button2_Click calls the function "saveInfoToDatabase" with the right parameters.
-- hope this helps
malhar
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
dim rx As New Regex("(?<ssl_result>ssl_r esult) = (?<ssl_result_Value> .*)\s (?<ssl_result_message>ssl_ result_mes sage) = (?<ssl_result_message_Valu e> .*)\s (?<ssl_txn_id>ssl_txn_id) = (?<ssl_txn_id_Value> .* )\s (?<ssl_approval_code>ssl_a pproval_co de) = (?<ssl_approval_code_Value > .* )\s (?<ssl_cvv2_response>ssl_c vv2_respon se) = (?<ssl_cvv2_response_Value > .* )\s (?<ssl_avs_response>ssl_av s_response ) = (?<ssl_avs_response_Value> .* )\s (?<ssl_transaction_type>ss l_transact ion_type) = (?<ssl_transaction_type_Va lue> .* )\s (?<ssl_amount>ssl_amount) = (?<ssl_amount_Value> .* )", RegexOptions.IgnoreCase Or RegexOptions.Multiline Or RegexOptions.IgnorePattern Whitespace Or RegexOptions.Compiled)
Dim match As Match = rx.Match("ssl_result=abc ssl_result_message=NOT_APP ROVED ssl_txn_id=123-456-7890-12 3456 ssl_approval_code=99999999 99AAANNN!! ! ssl_cvv2_response=P ssl_avs_response=X ssl_transaction_type=SALE ssl_amount=5323")
Dim mySQLStr As String
Dim ssl_result_Value, ssl_result_message_Value, ssl_txn_id_Value, ssl_approval_code_Value, ssl_cvv2_response_Value, ssl_avs_response_Value, ssl_transaction_type_Value , ssl_amount_Value As String
ssl_result_Value = match.Groups("ssl_result_V alue").Val ue
ssl_result_message_Value = match.Groups("ssl_result_m essage_Val ue").Value
ssl_txn_id_Value = match.Groups("ssl_txn_id_V alue").Val ue
ssl_approval_code_Value = match.Groups("ssl_approval _code_Valu e").Value
ssl_cvv2_response_Value = match.Groups("ssl_cvv2_res ponse_Valu e").Value
ssl_avs_response_Value = match.Groups("ssl_avs_resp onse_Value ").Value
ssl_transaction_type_Value = match.Groups("ssl_transact ion_type_V alue").Val ue
ssl_amount_Value = match.Groups("ssl_amount_V alue").Val ue
Try
mySQLStr = "insert into YOUR_TABLE_NAME (ssl_result_Value_columnNa me,ssl_res ult_messag e_Value_co lumnName , ssl_txn_id_Value_columnNam e, ssl_approval_code_Value_co lumnName,s sl_cvv2_re sponse_Val ue_columnN ame ,ssl_avs_response_Value_co lumnName,s sl_transac tion_type_ Value_colu mnName,ssl _amount_Va lue_column Name) values (" & _
"'" & ssl_result_Value & "', '" & ssl_result_message_Value & "', '" & ssl_txn_id_Value & "', '" & ssl_approval_code_Value & "', '" & ssl_cvv2_response_Value & "', '" & ssl_avs_response_Value & "', '" & ssl_transaction_type_Value & "', '" & ssl_amount_Value & "')"
MsgBox(mySQLStr) '<------ can not use msgbox in asp
If saveInfoToDatabase(mySQLSt r) Then
MessageBox.Show("Saved") '<------ can not use messagebox.show in asp
Else
MessageBox.Show("Not saved") '<------ can not use messagebox.show in asp
End If
Catch ex As Exception
MsgBox("error occured") '<------ can not use msgbox in asp
End Try
End Sub
Public Function saveInfoToDatabase(ByVal insertString As String) As Boolean
saveInfoToDatabase = False
Dim ds As New DataSet()
Try
Dim myConn As New SqlConnection("YOUR CONNECTION STRING")
Dim mySC As New SqlCommand(insertString, myConn)
Dim adp As New SqlDataAdapter(mySC)
adp.Fill(ds)
saveInfoToDatabase = True
Catch ex As Exception
MessageBox.Show("error occured - " & ex.ToString)
End Try
End Function
-- hope this helps
malhar
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
dim rx As New Regex("(?<ssl_result>ssl_r
Dim match As Match = rx.Match("ssl_result=abc ssl_result_message=NOT_APP
Dim mySQLStr As String
Dim ssl_result_Value, ssl_result_message_Value, ssl_txn_id_Value, ssl_approval_code_Value, ssl_cvv2_response_Value, ssl_avs_response_Value, ssl_transaction_type_Value
ssl_result_Value = match.Groups("ssl_result_V
ssl_result_message_Value = match.Groups("ssl_result_m
ssl_txn_id_Value = match.Groups("ssl_txn_id_V
ssl_approval_code_Value = match.Groups("ssl_approval
ssl_cvv2_response_Value = match.Groups("ssl_cvv2_res
ssl_avs_response_Value = match.Groups("ssl_avs_resp
ssl_transaction_type_Value
ssl_amount_Value = match.Groups("ssl_amount_V
Try
mySQLStr = "insert into YOUR_TABLE_NAME (ssl_result_Value_columnNa
"'" & ssl_result_Value & "', '" & ssl_result_message_Value & "', '" & ssl_txn_id_Value & "', '" & ssl_approval_code_Value & "', '" & ssl_cvv2_response_Value & "', '" & ssl_avs_response_Value & "', '" & ssl_transaction_type_Value
MsgBox(mySQLStr) '<------ can not use msgbox in asp
If saveInfoToDatabase(mySQLSt
MessageBox.Show("Saved") '<------ can not use messagebox.show in asp
Else
MessageBox.Show("Not saved") '<------ can not use messagebox.show in asp
End If
Catch ex As Exception
MsgBox("error occured") '<------ can not use msgbox in asp
End Try
End Sub
Public Function saveInfoToDatabase(ByVal insertString As String) As Boolean
saveInfoToDatabase = False
Dim ds As New DataSet()
Try
Dim myConn As New SqlConnection("YOUR CONNECTION STRING")
Dim mySC As New SqlCommand(insertString, myConn)
Dim adp As New SqlDataAdapter(mySC)
adp.Fill(ds)
saveInfoToDatabase = True
Catch ex As Exception
MessageBox.Show("error occured - " & ex.ToString)
End Try
End Function
ASKER
ok, thanks. i get these errors...
type 'Regex' is not defined
type 'Match' is not defined
i am fine with writing the sql connection, etc.
thanks!
type 'Regex' is not defined
type 'Match' is not defined
i am fine with writing the sql connection, etc.
thanks!
you'll need to add "imports System.Text.RegularExpress ions" in the beginning
so
-------------------------- --------
option explicit on
option strict on
imports System.Text.RegularExpress ions
imports .... other imports
public class class1
... stuff
end class
so
--------------------------
option explicit on
option strict on
imports System.Text.RegularExpress
imports .... other imports
public class class1
... stuff
end class
or do the following
right click on your project from the solution explorer, and select Add References. From the ".net refernces" select "System.Text.RegularExpres sions".
right click on your project from the solution explorer, and select Add References. From the ".net refernces" select "System.Text.RegularExpres
ASKER
ok, thanks! that took away those errors.
i am having a hard time understanding this part...
Dim match As Match = rx.Match("ssl_result=abc ssl_result_message=NOT_APP ROVED ssl_txn_id=123-456-7890-12 3456 ssl_approval_code=99999999 99AAANNN!! ! ssl_cvv2_response=P ssl_avs_response=X ssl_transaction_type=SALE ssl_amount=5323")
the string is all spelled out. i will not know what the string results are in my code. how will i know what to write, when i will just have my string?
i am having a hard time understanding this part...
Dim match As Match = rx.Match("ssl_result=abc ssl_result_message=NOT_APP
the string is all spelled out. i will not know what the string results are in my code. how will i know what to write, when i will just have my string?
ASKER
ok, i got past my last question, i just placed my string in the match box and that did the trick.
BUT, the parsing is not taking out all the extra spaces. this is my returned test sql statement:
insert into YOUR_TABLE_NAME (ssl_result_Value_columnNa me,ssl_res ult_messag e_Value_co lumnName , ssl_txn_id_Value_columnNam e, ssl_approval_code_Value_co lumnName,s sl_cvv2_re sponse_Val ue_columnN ame ,ssl_avs_response_Value_co lumnName,s sl_transac tion_type_ Value_colu mnName,ssl _amount_Va lue_column Name) values ('0
', 'APPROVED
', '00000000-0000-0000-0000-0 0000000000 0
', '123456
', 'P
', 'X
', 'SALE
', '53
')
how do i get rid of these extra spaces?
thanks!
BUT, the parsing is not taking out all the extra spaces. this is my returned test sql statement:
insert into YOUR_TABLE_NAME (ssl_result_Value_columnNa
', 'APPROVED
', '00000000-0000-0000-0000-0
', '123456
', 'P
', 'X
', 'SALE
', '53
')
how do i get rid of these extra spaces?
thanks!
i dont see the extra spaces. if you're wondering about the space between
ssl_cvv2_response_Value_co lumnName ,ssl_avs_response_Value_co lumnName
|_________________________ __________ _<<< this extra space, then you should not care about it . those are ignored by your SQL parser.
or you can force it to trim your answers
e.g
ssl_result_Value = trim(match.Groups("ssl_res ult_Value" ).Value)
ssl_result_message_Value = trim(match.Groups("ssl_res ult_messag e_Value"). Value)
ssl_txn_id_Value = trim(match.Groups("ssl_txn _id_Value" ).Value)
ssl_approval_code_Value = trim(match.Groups("ssl_app roval_code _Value").V alue)
ssl_cvv2_response_Value = trim(match.Groups("ssl_cvv 2_response _Value").V alue)
ssl_avs_response_Value = trim(match.Groups("ssl_avs _response_ Value").Va lue)
ssl_transaction_type_Value = trim(match.Groups("ssl_tra nsaction_t ype_Value" ).Value)
ssl_amount_Value = trim(match.Groups("ssl_amo unt_Value" ).Value)
ssl_cvv2_response_Value_co
|_________________________
or you can force it to trim your answers
e.g
ssl_result_Value = trim(match.Groups("ssl_res
ssl_result_message_Value = trim(match.Groups("ssl_res
ssl_txn_id_Value = trim(match.Groups("ssl_txn
ssl_approval_code_Value = trim(match.Groups("ssl_app
ssl_cvv2_response_Value = trim(match.Groups("ssl_cvv
ssl_avs_response_Value = trim(match.Groups("ssl_avs
ssl_transaction_type_Value
ssl_amount_Value = trim(match.Groups("ssl_amo
i'm assuming your columns are all type string/varchar/nvarchar . so when create the output string, i'm appending the single quotation mark.
e.g. insert into tableDemo(firstName, lastName) values ('John','Markson')
but if you were to insert a number you would NOT add quotation marks .. so it'd be like this
insert into tableDemo(firstName,lastNa me,age) values ('John','Markson',20)
e.g. insert into tableDemo(firstName, lastName) values ('John','Markson')
but if you were to insert a number you would NOT add quotation marks .. so it'd be like this
insert into tableDemo(firstName,lastNa
ASKER
ok, i see, so just to clarify SQL doesn't care if i have this with the extra spaces?
INSERT INTO myTable (ss_result, ssl_result_message) VALUES ('APPROVED ', 'CREDIT CARD APPROVED ')
?
INSERT INTO myTable (ss_result, ssl_result_message) VALUES ('APPROVED ', 'CREDIT CARD APPROVED ')
?
TGIF!
if you're gonna have more than one space separating the columns or params ... then you should change the regular expression. but if you don't change the regular expresion, my suggestion above for trimming your values will trim leading and following spaces .. so
let's say
dim myString as string = " John Markson "
msgbox (trim(myString) ) ---- would give you "John Markson" without the quotes!!
but here's a different approach ... it's upto your taste! :) i've changed \s to \s+ .. (\s means ignore 1 space ... \s+ means ignore 1 or more spaces)
dim rx As New Regex("(?<ssl_result>ssl_r esult) = (?<ssl_result_Value> .*)\s+ (?<ssl_result_message>ssl_ result_mes sage) = (?<ssl_result_message_Valu e> .*)\s+ (?<ssl_txn_id>ssl_txn_id) = (?<ssl_txn_id_Value> .* )\s+ (?<ssl_approval_code>ssl_a pproval_co de) = (?<ssl_approval_code_Value > .* )\s+ (?<ssl_cvv2_response>ssl_c vv2_respon se) = (?<ssl_cvv2_response_Value > .* )\s+ (?<ssl_avs_response>ssl_av s_response ) = (?<ssl_avs_response_Value> .* )\s+ (?<ssl_transaction_type>ss l_transact ion_type) = (?<ssl_transaction_type_Va lue> .* )\s+ (?<ssl_amount>ssl_amount) = (?<ssl_amount_Value> .* )", RegexOptions.IgnoreCase Or RegexOptions.Multiline Or RegexOptions.IgnorePattern Whitespace Or RegexOptions.Compiled)
if you're gonna have more than one space separating the columns or params ... then you should change the regular expression. but if you don't change the regular expresion, my suggestion above for trimming your values will trim leading and following spaces .. so
let's say
dim myString as string = " John Markson "
msgbox (trim(myString) ) ---- would give you "John Markson" without the quotes!!
but here's a different approach ... it's upto your taste! :) i've changed \s to \s+ .. (\s means ignore 1 space ... \s+ means ignore 1 or more spaces)
dim rx As New Regex("(?<ssl_result>ssl_r
ASKER
ok, something weird is happening. it's placing some sort of hidden soft return after the values and i guess adding the + after the s doesn't take care of it. do you have any idea what this is? i have my results populated in a text box and it automatically goes to the next line after each value. ??
insert into YOUR_TABLE_NAME (ssl_result_Value_columnNa me,ssl_res ult_messag e_Value_co lumnName , ssl_txn_id_Value_columnNam e, ssl_approval_code_Value_co lumnName,s sl_cvv2_re sponse_Val ue_columnN ame ,ssl_avs_response_Value_co lumnName,s sl_transac tion_type_ Value_colu mnName,ssl _amount_Va lue_column Name) values ('0
', 'APPROVED
', '00000000-0000-0000-0000-0 0000000000 0
', '123456
', 'P
', 'X
', 'SALE
', '53
')
insert into YOUR_TABLE_NAME (ssl_result_Value_columnNa
', 'APPROVED
', '00000000-0000-0000-0000-0
', '123456
', 'P
', 'X
', 'SALE
', '53
')
what you can do is .... this will replace all the "non-visible" carriage return characters with a zero lenght string.
string.replace(YOUR_STRING _VALUE_FRO M_CREDIT_C ARD_COMPAN Y,chr(13), "")
string.replace(YOUR_STRING _VALUE_FRO M_CREDIT_C ARD_COMPAN Y,chr(10), "")
string.replace(YOUR_STRING _VALUE_FRO M_CREDIT_C ARD_COMPAN Y,vbcrlf," ")
good luck
string.replace(YOUR_STRING
string.replace(YOUR_STRING
string.replace(YOUR_STRING
good luck
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER