I am using VS Express 2012, SQL Server 2012. I have one table (computers) and two rows with 10 columns (HaHu_ID, Serial_Number, Brand, Model, OS, Processor, HDD, Memory, ST, Speed).
I've been on this site reading as many posts as I can trying to create a vb.net interface to a SQL Server. I succeed at connecting them and returning the values to a DataGridView table with a
SELECT * FROM computers
BUT when I tried other commands like
SELECT * FROM computers
WHERE 'HaHu_ID' = '101'
it returns an empty DataGridView row! Tried changing up 'HaHu_ID' to something random, but it still gave me empty rows. The correct column names are displayed but the rows are all empty.
When I tried another command "SELECT 'HaHu_ID', 'Brand' FROM computers" and it returned:
Column1---|--Column2
-HaHu_ID--|--Brand
-HaHu_ID--|--Brand
The column names have been changed to "Column1 and column2" and as you can see the rows are filled with what should be the column names! Frustrated I tried "SELECT 'HaHu', 'Brand_ID' FROM computers" (non existing columns in my database) and it returned with:
Column1---|--Column2
---HaHu----|--Brand_ID
----HaHu---|--Brand_ID
I went back to the original SELECT * FROM computers and it works again!
Here is my code:
Dim cs as New SqlConnection...
cs.Open()
'Dim da2 as New SqlDataAdapter("SELECT * FROM computers WHERE 'HaHu_ID' = '101'", cs)
Dim da2 as New SqlDataAdapter("SELECT * FROM computers", cs)
Dim table as New DataTable()
table.Locale = System.Globalization.CultureInfo.InvariantCulture
da2.Fill(table)
BindingSource1.DataSource = table
dataGrid1.DataSource = BindingSource1
cs.Close()
(I couldn't copy and paste it because I'm on another computer now). So the select * from computers statement works perfectly but as soon as I try something else it doesn't work.
Why is that? Thanks.