07-22-2012, 02:21 AM
I have Made a database of (ID,Name.Age) and do the following codes , it doesn't work , Please guide me what can I do
Note :- I am not good in Programming
[code2=vbnet]Imports System.Data.SqlClient
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
ListBox2.Items.Add(ListBox1.SelectedItem)
ListBox1.Items.Remove(ListBox1.SelectedItem)
End Sub
Public Sub calculate()
Dim IDS As New List(Of Double)
Dim Names As New List(Of String)
Dim ages As New List(Of Double)
For Each item In ListBox2.Items
Dim itemName As String = item.ToString
Dim ID As Double
Dim age As Double
Dim conn As New SqlConnection("Data Source=C:\Users\QaziNasir\documents\visual studio 2010\Projects\NSfile\NSfile\NDatabase.sdf")
Dim sqlquery As String = "SELECT * From NSTable = '" & itemName & "'"
Dim command As New SqlCommand
command.Connection = conn
command.CommandText = sqlquery
Dim adapter As New SqlDataAdapter
adapter.SelectCommand = command
Dim Data As SqlDataReader
conn.Open()
Data = command.ExecuteReader
While Data.Read
ID = CDbl(Data(1))
Name = CDbl(Data(2))
age = CDbl(Data(3))
End While
Data.Close()
conn.Close()
IDS.Add(ID)
ages.Add(age)
Names.Add(itemName)
Next
End Sub
End Class[/code2]
Note :- I am not good in Programming
[code2=vbnet]Imports System.Data.SqlClient
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
ListBox2.Items.Add(ListBox1.SelectedItem)
ListBox1.Items.Remove(ListBox1.SelectedItem)
End Sub
Public Sub calculate()
Dim IDS As New List(Of Double)
Dim Names As New List(Of String)
Dim ages As New List(Of Double)
For Each item In ListBox2.Items
Dim itemName As String = item.ToString
Dim ID As Double
Dim age As Double
Dim conn As New SqlConnection("Data Source=C:\Users\QaziNasir\documents\visual studio 2010\Projects\NSfile\NSfile\NDatabase.sdf")
Dim sqlquery As String = "SELECT * From NSTable = '" & itemName & "'"
Dim command As New SqlCommand
command.Connection = conn
command.CommandText = sqlquery
Dim adapter As New SqlDataAdapter
adapter.SelectCommand = command
Dim Data As SqlDataReader
conn.Open()
Data = command.ExecuteReader
While Data.Read
ID = CDbl(Data(1))
Name = CDbl(Data(2))
age = CDbl(Data(3))
End While
Data.Close()
conn.Close()
IDS.Add(ID)
ages.Add(age)
Names.Add(itemName)
Next
End Sub
End Class[/code2]