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! 4 1476
Cast your date into a DateTime object. Then use the string output
method that meets your formatting needs.
//Pass in year, month and day here from your database records
DateTime myDate = new DateTime(year,month, day);
myDate.ToShortDateString():
Joseph wrote:
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!
Joseph wrote:
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!
Joseph,
Like Matt says, except to get the date format you need (which I assume
is MMDDYYY and not DDMMYYYY) you can use this format string:
dt.ToString("MMddyyyy")
Where dt is the DateTime object Matt refers to.
-Jay
Thanks for replying guys.
Additionally: Would you use a dataset or datareader to perfom this? Can you
provide a snippet of code that would demonstrate how to actually capture the
data from the database and put into a variable. Thanks
"Jay Riggs" wrote:
>
Joseph wrote:
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!
Joseph,
Like Matt says, except to get the date format you need (which I assume
is MMDDYYY and not DDMMYYYY) you can use this format string:
dt.ToString("MMddyyyy")
Where dt is the DateTime object Matt refers to.
-Jay
Joseph wrote:
Thanks for replying guys.
Additionally: Would you use a dataset or datareader to perfom this? Can you
provide a snippet of code that would demonstrate how to actually capture the
data from the database and put into a variable. Thanks
"Jay Riggs" wrote:
Joseph wrote:
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!
Joseph,
Like Matt says, except to get the date format you need (which I assume
is MMDDYYY and not DDMMYYYY) you can use this format string:
dt.ToString("MMddyyyy")
Where dt is the DateTime object Matt refers to.
-Jay
Hi Joseph,
I'd use a data reader.
Here's a sample project using a DataReader: http://www.codeproject.com/dotnet/adonet_datareader.asp
See this link for a discussion of your options (see specifically the
section entitled "Working with DataReaders, DataSets, DataAdapters, and
DataViews"): http://msdn2.microsoft.com/en-us/lib...netbest_topic3
See this link for a DataReader/ DataSet comparison: http://msdn.microsoft.com/msdnmag/is...06/DataPoints/
HTH
-Jay This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Rob Meade |
last post by:
Lo all,
I have a local recordset which is not linked to a database.
Some of the fields in this recordset contain html tags.
I have a function which is called when I'm calculating my...
|
by: Tom |
last post by:
I want to open a recordset object on an .asp page. When I open the
recordset I would like to use a stored procedure that expects a parameter to
be passed for the stored procedure. I will then use...
|
by: Tom Lee |
last post by:
Hi Guys,
Firstly thanks for all the help you have providing me...
I have another question I was stuck with.
Here is a simple code
dim strsql as string
dim scr as recordset
|
by: Simone |
last post by:
Hello
I hope you guys can help me. I am very new to ADO...
I am creating a ADODB connection in a module and trying to access it
from a command button in a form.
Function fxEIDAssgn(plngEID As...
|
by: Lyn |
last post by:
Hi,
I am opening a form in Continuous mode to list the records from a recordset
created in the calling form. The recordset object is declared as Public and
is set into the new form's Recordset...
|
by: Marathoner |
last post by:
I have read Bill Vaughn's paper on this subject and I have one stumbling
block. Bill wrote his demo in VB.NET. He converts a DataTable to an XML
file. In VB.NET, he dimmed a recordset and used...
|
by: kjvt |
last post by:
Based on a prior posting, I've written a function to convert a
recordset to a dataview. The first call to the function for a given
recordset works perfectly, but the second call always returns a...
|
by: tdr |
last post by:
I need to compare table 1 to table 2 and if the row/recordset in
table 1 is different from table 2, write the entire row/recordset
from table 1 to table 3.
I can read an entire row/recordset ...
|
by: =?Utf-8?B?R1ROMTcwNzc3?= |
last post by:
Hi Guys, thanks for your help yesterday, I've got one more question, then I
think I'm done for now,...
Is it possible to insert recordset data in a javascript, for instance I have
a javascript...
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
| |