我已經在VB.net應用程序中開發了一個字導出函數,該函數返回列(service_name)中具有特定值的所有行。但是,當循環遍歷函數時,單詞中的單元格總是抓取第一個服務名稱,而不是循環遍歷每個服務名稱。我需要一種可以指向特定service_name的下一個值的方式。SQL獲取所有行值VB.net
我已經給我掠從價值和出口詞明知有相匹配的價值,但總是返回的第一個其中3個行的表的預覽。
功能用於返回SQL數據:
Function getdataapplication(ByVal recordnum As Integer, ByVal fieldnum As Integer)
ds.Reset()
GC.Collect()
Dim dbtable
dbtable = "application_portfolio"
Dim sql As MySqlCommand
sql = New MySqlCommand("Select * from application_portfolio where service_name = '" & Wordexport.tbservicename.Text & "' ", dbcon)
Dim DataAdapter1 As MySqlDataAdapter = New MySqlDataAdapter()
DataAdapter1.SelectCommand = sql
DataAdapter1.Fill(ds, dbtable)
dbcon.Close()
sql.Dispose()
Return ds.Tables(dbtable).rows(recordnum).Item(fieldnum - 1)
'Return reader
End Function
Public Sub Word_Click(sender As Object, e As EventArgs) Handles Word.Click
Dim sqlrowcount As Integer
sqlrowcount = CountRecords()
tbcount.Text = sqlrowcount
If application_portfolio.Checked = True Then
'oWord.NewDocument.Application.Equals(Nothing)
Dim oPara2application As Word.Paragraph
Dim oTableapplication As Word.Table
For i As Integer = 1 To sqlrowcount
j = j + 1
oTableapplication = oDoc.Tables.Add(oDoc.Bookmarks.Item("\endofdoc").Range, j, 7)
oTableapplication.Range.ParagraphFormat.SpaceAfter = 6
oTableapplication.Rows(1).Range.Font.Bold = True
oTableapplication.Cell(1, 1).Range.Text = "ID"
oTableapplication.Cell(1, 2).Range.Text = "Service Name"
oTableapplication.Cell(1, 3).Range.Text = "Application Name"
oTableapplication.Cell(1, 4).Range.Text = "Application Type"
oTableapplication.Cell(1, 5).Range.Text = "Cost"
oTableapplication.Cell(1, 6).Range.Text = "Year Released"
oTableapplication.Cell(1, 7).Range.Text = "Version"
Dim tempdatastore = getdataapplication(0, 1)
ListBox1.Items.Add(tempdatastore)
oTableapplication.Cell(j, 1).Range.Text = functions.getdataapplication(0, 1)
oTableapplication.Cell(j, 2).Range.Text = functions.getdataapplication(0, 2)
oTableapplication.Cell(j, 3).Range.Text = functions.getdataapplication(0, 3)
oTableapplication.Cell(j, 4).Range.Text = functions.getdataapplication(0, 4)
oTableapplication.Cell(j, 5).Range.Text = functions.getdataapplication(0, 5)
oTableapplication.Cell(j, 6).Range.Text = functions.getdataapplication(0, 6)
oTableapplication.Cell(j, 7).Range.Text = functions.getdataapplication(0, 7)
oTableapplication.Rows.Item(1).Range.Font.Italic = True
Next
End If
End function
謝謝你的工作:) 我也必須改變爲我作爲整數= 0到sqlrowcount -1 – user3013243