2016-11-15 59 views
-1

你能告訴我如何從0-5歲得等從SQL Server和輸入文本框或標籤總數是多少?請點擊鏈接樣本 Generate Ages從sql server生成時代。 VB.NET

謝謝!

+1

我們可以看到你的代碼?而且,你的目標能更明確嗎?我不明白什麼你願意做... – romulus001

+0

現在我沒有這個尚未代碼,因爲我不知道如何下手! 對不起,我的英語。我想從例如1-5歲或6-10歲的年齡中獲得年齡,並且總結他們在那個年齡的城鎮中有多少男性和女性1。 –

+0

請閱讀[問]。重要短語:「搜索和研究」和「解釋......阻止你自己解決它的任何困難」。 –

回答

0

你的意思是這樣

Dim sql As String = "SELECT age_column FROM your_table WHERE age_column BETWEEN '0' AND '5'" 
'The above line selects the all records where age is between 0-5 (Change the variables) 

Dim da As New OleDbDataAdapter(sql, connectionstring) 
Dim ds As New DataSet 
Dim dt as new DataTable 

da.Fill(ds) 
dt = ds.Tables(0).Copy() 

' Above code stores the results in an iterable table 

Dim i As Integer = 0 

For Each dr as DataRow in dt.Rows 
i = i + 1 
Next 

TextBox1.Text = i 

'i will be the total number of records where age is between 0-5, and display it in a `TextBox` 

你的問題,但是,很可憐,通常人們不會把過多的精力投入到回答它,因爲你已經把沒有努力在自己身上。

+0

讚賞!對於我這個可憐的問題,我很抱歉,因爲我有一個小小的英語詞彙。我會給這一槍! –

+0

@YevrahAradnop你已經有一個打開連接的連接字符串了嗎?這僅僅是如果你使用'MS-Access'過,或者你正在使用'OleDb'另一個DBMS – David

+0

上面的代碼就是我要找的。是的,我已經有一個連接字符串,但我的問題是這樣的代碼。也許我現在需要一些新鮮空氣。非常感謝! –