473,383 Members | 1,922 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

VB recordset to ADO.Net question

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!

Nov 13 '06 #1
4 1496
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!
Nov 13 '06 #2

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

Nov 13 '06 #3
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

Nov 13 '06 #4
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

Nov 13 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
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...
4
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...
1
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
5
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...
2
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...
2
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...
36
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...
7
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 ...
4
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.