Select a cell in Datagridview to display details in combo boxes and textbox

dawnKo

Member
Joined
Jul 10, 2006
Messages
11
Programming Experience
Beginner
Hi, need help urgently..:( mmm.. I m using sql server 2005 and visual studio 2005... i have 2 queries on visual basic codings and sql statement...
1) How can i retrieve previous year in sql statement to display in datagrid??
Select * From table1 Where Year = Now.Year And year = Now.Year -1
After inserting this line, there is nth appearing in the datagrid at all.. can anyone tell me what is wrong?

2) I would like to do a function that enable user to click on a cell and details regarding that row of datagrid will be display in 3 combo boxes and a textbox. How can i do this?

;)
Many thanks in advance....
 
This needs to be two different postings. I'll answer the first.

1) How can i retrieve previous year in sql statement to display in datagrid??
Select * From table1 Where Year = Now.Year And year = Now.Year -1
After inserting this line, there is nth appearing in the datagrid at all.. can anyone tell me what is wrong?

A year CANNOT equal both the current year (2006) and the previous year (2005). Its one OR the other.

What exactly are you inserting? Your select should look something like this...

SELECT * FROM table1
WHERE Year = Now.Year OR Year = Now.Year - 1
 
Hi, thanks for helping:) What i want is to retrieve all the records from year 2005 to 2006 so if year cannot equal to current year and previous year. How can i retrieve records from both year?? This is my coding:

selectCmd = "SELECT * FROM [table1] INNER JOIN [table2] ON [table1].[Project No] = [table2].[Project No] WHERE([table2].[Name] = @Name) AND ([table1].Year = '" & Now.Year And Now.Year -1 "') ORDER BY [table1].Year DESC"


An error that say Conversion from string to type 'Long' is not valid.
 
Last edited:
Hi this is what i would use in 2003
VB.NET:
SELECT    [table1].*
FROM [table1] INNER JOIN
[table2] ON [table1].1_ANID = [table2].2_ANID
WHERE ([table2].Name = @Name) 
AND ([table1].IntYear = DATEPART(year, GETDATE()) 
OR [table1].IntYear = DATEPART(year, GETDATE()) -1)
[SIZE=2][COLOR=#008000]ORDER BY [table1].IntYear DESC
[/COLOR][/SIZE]
Note:
the IntYear in column in table1 is not a date but an integer
The current year and perivious year are split but need to bracketed together

g
 
Back
Top