2010-06-05 3 views
0

나는 다음과 같은 필드 SQLite는 테이블이 있습니다vb.net의 SQLite는 방법을 선택한 레코드를 통해 루프와 다른 함수에 매개 변수로 각 레코드를 통과 할

Langauge  level  hours 
German  2   50 
French  3   40 
English 1   60 
German  1   10 
English 2   50 
English 3   60 
German  1   20 
French  2   40 

내가 언어를 기반으로 기록을 반복하고 싶지 및 다른 조건을 적용한 다음 현재 선택된 레코드를 다른 기능으로 전달합니다. 그래서 실제 코드와 psudo 코드가 다음과 같이 혼합되어 있습니다. psudo 코드를 실제 코드로 변환하는 데 도움이 필요합니다. 나는 그렇게하기가 어렵다. 당신의 도움에 대한

Private sub mainp() 
    Dim oslcConnection As New SQLite.SQLiteConnection 
    Dim oslcCommand As SQLite.SQLiteCommand 
    Dim langs() As String = {"German", "French", "English"} 
    Dim i as Integer = 0 
    oslcConnection.ConnectionString = "Data Source=" & My.Settings.dbFullPath & ";" 
    oslcConnection.Open() 
    oslcCommand = oslcConnection.CreateCommand 
    Do While i <= langs.count 
    If langs(i) = "German" Then 
     oslcCommand.CommandText = "SELECT * FROM table WHERE language = '" & langs(i) & "';" 
     For each record selected    'psudo code 
     If level = 1 Then     'psudo code 
      update level to 2    'psudo code 
      minorp(currentRecord)   'psudo code: calling minorp function and passing the whole record as a parameter 
     End If       'psudo code 
     If level = 2 Then     'psudo code 
      update level to 3    'psudo code 
      minorp(currentRecord)   'psudo code: calling minorp function and passing the whole record as a parameter 
     End If       'psudo code 
     Next         'psudo code 
    End If 

    If langs(i) = "French" Then 
     oslcCommand.CommandText = "SELECT * FROM table WHERE language = '" & langs(i) & "';" 
     For each record selected    'psudo code 
     If level = 1 Then     'psudo code 
      update level to 2    'psudo code 
      minorp(currentRecord)   'psudo code: calling minorp function and passing the whole record as a parameter 
     End If       'psudo code 
     If level = 2 Then     'psudo code 
      update level to 3    'psudo code 
      minorp(currentRecord)   'psudo code: calling minorp function and passing the whole record as a parameter 
     End If       'psudo code 
     Next         'psudo code 
    End If 
Loop 
End Sub 

많은 감사를 : 여기에

내가 가진 것입니다.

답변

1

데이터 테이블에는 함수에 전달할 수있는 DataRow 개체가 있습니다.

+0

제발 보여줄 수있는 방법 sqlite 함께 할. vb.net 및 sqlite를 사용하여 예제를 찾는 데 어려움을 겪고 있습니다. 감사합니다 – mazrabul

+0

글쎄, 의사 코드를 표시하고 있기 때문에 당신이 쿼리에서 DataSet 또는 DataReader를 얻고 있다고 가정하고 있습니다. DataTable 및 DataReader 클래스를 확인하십시오. 둘 다 DataRows 컬렉션 (DataReader의 행?)을 가지고 있습니다. – Raj

+0

예, 데이터 집합을 사용하고 있습니다. 수업을 확인하고 내가 뭘 찾았는지 알았어. 감사 – mazrabul

0

클래스를 만들 것을 제안합니다.

public class LanguageCourse 

    'Prob better to make these properties 
    public Language as string 
    public Level as integer 
    public Hours as integer 

    public sub new(language as string, level as integer, hours as integer) 
    Language = language 
    Level = level 
    Hours = hours 
    end sub 

end class 

다음이 될 수 위의 코드 :이 :) 컴파일되지 않습니다

0

난 당신이 논리를 이동 제안으로이 의사 코드는 여전히 것을

Private sub mainp() 
    Dim oslcConnection As New SQLite.SQLiteConnection 
    Dim oslcCommand As SQLite.SQLiteCommand 
    Dim langs() As String = {"German", "French", "English"} 
    Dim i as Integer = 0 
    oslcConnection.ConnectionString = "Data Source=" & My.Settings.dbFullPath & ";" 
    oslcConnection.Open() 
    oslcCommand = oslcConnection.CreateCommand 

    'Not sure why you were looping round these like this. It's also not a great idea to 
    'build up your sql queries by concactenating strings, better to parameteris them, but 
    'seeing as how this seems to be hard coded anyway, better even like this: 

     dim course as LanguageCourse 

     oslcCommand.CommandText = "SELECT * FROM table WHERE language IN ("German", "French", "English");" 
     For each record selected    'psudo code 

     course = new LanguageCourse(record.language, record.level, record.hours) 

     'This function should handle your update as you just seem to be adding one to 
     'something, for certain criteria. 
     minorp(course) 

     Next         'psudo code 


End Sub 

주 데이터베이스 SQL은 이러한 점검을 수행하고 update 절을 통해 where 절을 사용하여 데이터를 갱신 할 수 있습니다.

관련 문제