G
Guest
Hi all-
I am a former VB6 programmer and new at C# and I have a question dealing
with converting some code from VB6 to C#. The code is below and essentially,
what it does is gets data from a SQL Server database and parses some of the
data and puts the parsed data into a text field. I omitted a some of the code
and left the data parsing part of it, which is what my question is about.
Exactly what the code below does is gets data from SQL Server and parses one
of the date fields. So if the date it retrieves is 1/9/2006, the parsing
outcome becomes:
01092006. I am not sure how to accomplish this in C#, being that I am no
longer dealing with a recorset and I'm not sure how to accomplish this using
a dataset or datareader.
VB Code:
Set rsRecordset = New Recordset
rsRecordset.Open (sSQL), adoConn, adOpenStatic, adLockOptimistic
Dim varNumber As Variant
Dim intDP As Integer
Dim sYY As String 'Pulls the year value from the recordset
Dim sMM As String 'Pulls the month value from the recordset
Dim sDD As String 'Pulls the day value from the recordset
Dim sAV As String 'Pulls the actual value from the recordset
Dim sIV As String 'Pulls the indicated value from the recordset
Dim iAV As String
Dim iIV As String
Dim iYY As String
Dim iMM As String
Dim iDD As String
sPrefix = ""
Do While Not rsRecordset.EOF
sYY = CStr(rsRecordset("YY")) 'the year
sMM = CStr(rsRecordset("MM")) 'the month
sDD = CStr(rsRecordset("DD")) 'the day
iYY = CInt(sYY)
iDD = CInt(sDD)
iMM = CInt(sMM)
If iYY < 10 Then sYY = "0" & iYY 'if the year digit is less then 10
add a zero
If iDD < 10 Then sDD = "0" & iDD 'same
If iMM < 10 Then sMM = "0" & iMM 'same
sAV = CStr(rsRecordset("AV")) 'Actual value
sIV = CStr(rsRecordset("IV")) 'Indicated value
iAV = CInt(sAV)
iIV = CInt(sIV)
If iAV < 10 Then sAV = "000" & CStr(rsRecordset("AV"))
If iIV < 10 Then sIV = "000" & CStr(rsRecordset("IV"))
If iAV >= 10 And iAV < 100 Then sAV = "00" & CStr(rsRecordset("AV"))
If iIV >= 10 And iAV < 100 Then sIV = "00" & CStr(rsRecordset("IV"))
If iAV >= 100 And iAV < 1000 Then sAV = "0" & CStr(rsRecordset("AV"))
If iIV >= 100 And iIV < 1000 Then sIV = "0" & CStr(rsRecordset("IV"))
Me.Text1.Text = Me.Text1.Text & sPrefix & "8" &
CStr(rsRecordset("ST")) & CStr(rsRecordset("CNTY")) _
& CStr(rsRecordset("SITE")) &
CStr(rsRecordset("PARMETER")) & CStr(rsRecordset("POC")) _
& CStr(rsRecordset("TMINT")) & "001" & "0" &
CStr(rsRecordset("MET")) _
& sYY & sMM & sDD & "0" & sAV & sIV & Space(41) & "I"
rsRecordset.MoveNext
sPrefix = vbCrLf
Loop
Thanks!
I am a former VB6 programmer and new at C# and I have a question dealing
with converting some code from VB6 to C#. The code is below and essentially,
what it does is gets data from a SQL Server database and parses some of the
data and puts the parsed data into a text field. I omitted a some of the code
and left the data parsing part of it, which is what my question is about.
Exactly what the code below does is gets data from SQL Server and parses one
of the date fields. So if the date it retrieves is 1/9/2006, the parsing
outcome becomes:
01092006. I am not sure how to accomplish this in C#, being that I am no
longer dealing with a recorset and I'm not sure how to accomplish this using
a dataset or datareader.
VB Code:
Set rsRecordset = New Recordset
rsRecordset.Open (sSQL), adoConn, adOpenStatic, adLockOptimistic
Dim varNumber As Variant
Dim intDP As Integer
Dim sYY As String 'Pulls the year value from the recordset
Dim sMM As String 'Pulls the month value from the recordset
Dim sDD As String 'Pulls the day value from the recordset
Dim sAV As String 'Pulls the actual value from the recordset
Dim sIV As String 'Pulls the indicated value from the recordset
Dim iAV As String
Dim iIV As String
Dim iYY As String
Dim iMM As String
Dim iDD As String
sPrefix = ""
Do While Not rsRecordset.EOF
sYY = CStr(rsRecordset("YY")) 'the year
sMM = CStr(rsRecordset("MM")) 'the month
sDD = CStr(rsRecordset("DD")) 'the day
iYY = CInt(sYY)
iDD = CInt(sDD)
iMM = CInt(sMM)
If iYY < 10 Then sYY = "0" & iYY 'if the year digit is less then 10
add a zero
If iDD < 10 Then sDD = "0" & iDD 'same
If iMM < 10 Then sMM = "0" & iMM 'same
sAV = CStr(rsRecordset("AV")) 'Actual value
sIV = CStr(rsRecordset("IV")) 'Indicated value
iAV = CInt(sAV)
iIV = CInt(sIV)
If iAV < 10 Then sAV = "000" & CStr(rsRecordset("AV"))
If iIV < 10 Then sIV = "000" & CStr(rsRecordset("IV"))
If iAV >= 10 And iAV < 100 Then sAV = "00" & CStr(rsRecordset("AV"))
If iIV >= 10 And iAV < 100 Then sIV = "00" & CStr(rsRecordset("IV"))
If iAV >= 100 And iAV < 1000 Then sAV = "0" & CStr(rsRecordset("AV"))
If iIV >= 100 And iIV < 1000 Then sIV = "0" & CStr(rsRecordset("IV"))
Me.Text1.Text = Me.Text1.Text & sPrefix & "8" &
CStr(rsRecordset("ST")) & CStr(rsRecordset("CNTY")) _
& CStr(rsRecordset("SITE")) &
CStr(rsRecordset("PARMETER")) & CStr(rsRecordset("POC")) _
& CStr(rsRecordset("TMINT")) & "001" & "0" &
CStr(rsRecordset("MET")) _
& sYY & sMM & sDD & "0" & sAV & sIV & Space(41) & "I"
rsRecordset.MoveNext
sPrefix = vbCrLf
Loop
Thanks!