2
그래서 내 코딩 문제가있어서 누구든지 나를 도울 수 있는지 궁금해하고있었습니다.주어진 범위에서 누락 된 숫자 찾기
기본적으로 나는 VB.NET과 MSSQL을 사용하여 사용자가 설정 한 주어진 범위 사이에 누락 된 숫자를 찾기위한 프로그램을 만들고 있습니다. 프로그램은 테이블에서 읽고 텍스트 상자에 출력을 보냅니다. 그리고 위의 코드는 지금까지 내가 생각해 낼 수있는 것입니다. 그러나 문제는 잘못된 결과물을 얻고 내가 원하는 것을 얻지 못한다는 것입니다. 출력은 image입니다.
Function FindingMissingNumber() As String
Dim intX As Integer = Nothing
Dim intY As Integer = Nothing
Dim strSting As String = Nothing
Dim strSqlQUery As String = Nothing
Dim cmdSqlCommand As Data.SqlClient.SqlCommand = Nothing
Dim rdrDataReader As Data.SqlClient.SqlDataReader = Nothing
'------------------------------------------------------------------------------------------------------------------------
'-> Process
'------------------------------------------------------------------------------------------------------------------------
strSqlQUery = "Select ExReportPolicyNo From DBReport Order by ExReportPolicyNo"
Dim msSqlConnection As New Data.SqlClient.SqlConnection()
'NOTE - You may need to CHECK your connection string!!! in the line below
msSqlConnection.ConnectionString = "Data Source=SISBSQL\SISBSQL;Initial Catalog=ExceptionReport;User ID=sa;Password=123;"
cmdSqlCommand = New Data.SqlClient.SqlCommand(strSqlQUery, msSqlConnection)
If cmdSqlCommand.Connection.State = Data.ConnectionState.Closed Then cmdSqlCommand.Connection.Open()
rdrDataReader = cmdSqlCommand.ExecuteReader()
If rdrDataReader.HasRows Then
Do While rdrDataReader.Read()
intX = txtRangeLeft.Text
intY = txtRangeRight.Text
'intY = rdrDataReader.GetValue(rdrDataReader.GetOrdinal("ExReportPolicyNo"))
Do While intX <> intY
intX = intX + 1
If intX <> intY Then
strSting = strSting & intX & ", " 'if it is not, then record the non sequential number into the string
Else
Exit Do
End If
Loop
Loop
End If
If cmdSqlCommand.Connection.State = Data.ConnectionState.Open Then cmdSqlCommand.Connection.Close()
'return string
Return strSting
'tidy up
intX = Nothing
intY = Nothing
strSting = Nothing
strSqlQUery = Nothing
cmdSqlCommand = Nothing
rdrDataReader = Nothing
End Function
프로그램에서 여러 번 반복하여 잘못된 출력을 제공합니다. 출력은 "286118, 286120, 286121"로만 읽어야합니다. 질문은 어디에 잘못 되었습니까?
위의 목록에서 CSV 문자열을 만들기 찾기? –
"x"를 어떻게 선언해야합니까? –
x을 선언 할 필요가 없습니다. –