Click here to Skip to main content
15,886,199 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: vb.net Pin
Richard MacCutchan22-Dec-11 1:04
mveRichard MacCutchan22-Dec-11 1:04 
AnswerRe: vb.net Pin
Luc Pattyn22-Dec-11 1:07
sitebuilderLuc Pattyn22-Dec-11 1:07 
AnswerRe: vb.net Pin
RaviRanjanKr23-Dec-11 10:27
professionalRaviRanjanKr23-Dec-11 10:27 
Questiongoogle maps in vb6 application Pin
Preeti197921-Dec-11 20:14
Preeti197921-Dec-11 20:14 
AnswerRe: google maps in vb6 application Pin
thatraja21-Dec-11 21:53
professionalthatraja21-Dec-11 21:53 
AnswerRe: google maps in vb6 application Pin
Dave Kreskowiak22-Dec-11 3:39
mveDave Kreskowiak22-Dec-11 3:39 
AnswerRe: google maps in vb6 application Pin
Eddy Vluggen23-Dec-11 7:31
professionalEddy Vluggen23-Dec-11 7:31 
QuestionHow to read relational databases Pin
Chris_B8421-Dec-11 7:28
Chris_B8421-Dec-11 7:28 
Hi. I am fairly new to VB. I am familiar with reading and writing to a flatfile database in VB and binding it with a datagrid but I have the following problem. I have googled it but couldnt find anything useful. It is a web application.

This was a technical test I had to complete at home in a 2 hour timeframe, for a job application. The 2 hours were from this morning and I already emailed back my attempt. However, I'm still trying to complete the task so that I can learn for future reference as I'm sure I'll encounter relational databases again.

The following are the two tables and their fields:

EMPLOYEE: Payroll (pri key), firstname, surname, department
DEPARTMENT: number (pri key), departmentname, manager

In the EMPLOYEE table, the department is the foreign key to the number in the DEPARTMENT table.

In the DEPARTMENT table, the manager is the foreign key to the payroll in the EMPLOYEE TABLE.

---------------------------------------------

On my form, I have a drop down list which displays the departmentnames from the DEPARTMENT table (these are retail, warehouse and management).

I also have a button and a gridview. When the button is clicked, the gridview should display records from the EMPLOYEE. It should only show the employees who work in the department that was selected in the datagrid. I have the following code at the start of the class:

VB
Dim con As SqlConnection
Dim dsDept As New DataSet
Dim dsEmployee As New DataSet
Dim daDept As SqlClient.SqlDataAdapter
Dim daEmployee As SqlClient.SqlDataAdapter
Dim sqlDept As String
Dim sqlEmployee As String


And I have this code on my button:

VB
con = New System.Data.SqlClient.SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\CivicaDB.mdf;Integrated Security=True;User Instance=True")

con.Open()
sqlDept = "SELECT * FROM Department"
daDept = New SqlClient.SqlDataAdapter(sqlDept, con)
daDept.Fill(dsDept, "Department")
con.Close()

Dim currentRow As Integer
currentRow = 0

Dim cmd As New SqlCommand

For Each DataRow In dsDept.Tables("Department").Rows
       If dsDept.Tables("Department").Rows(currentRow).Item("Name") = DropDownList1.SelectedValue Then

                Dim correctDept As Integer
                correctDept = dsDept.Tables("Department").Rows(currentRow).Item("Number")

                con.Open()
                sqlEmployee = "SELECT * FROM Employee WHERE Department =" & Convert.ToString(correctDept) & ";"
                daEmployee = New SqlClient.SqlDataAdapter(sqlEmployee, con)
                daEmployee.Fill(dsEmployee, "Employee")
                GridView1.DataSource = dsEmployee
                GridView1.DataBind()
                con.Close()

            End If

            currentRow = currentRow + 1
Next


Thanks for any help given Smile | :)
AnswerRe: How to read relational databases Pin
Framework .l.21-Dec-11 15:27
Framework .l.21-Dec-11 15:27 
QuestionSourcecode for control Scanner Pin
Muhammad Riadi20-Dec-11 3:01
Muhammad Riadi20-Dec-11 3:01 
AnswerRe: Sourcecode for control Scanner Pin
Dave Kreskowiak20-Dec-11 3:32
mveDave Kreskowiak20-Dec-11 3:32 
AnswerRe: Sourcecode for control Scanner Pin
Smithers-Jones20-Dec-11 22:52
Smithers-Jones20-Dec-11 22:52 
QuestionHow to delete record from DataGrid control VB Pin
rizaky201119-Dec-11 14:35
rizaky201119-Dec-11 14:35 
AnswerRe: How to delete record from DataGrid control VB Pin
Dave Kreskowiak20-Dec-11 3:33
mveDave Kreskowiak20-Dec-11 3:33 
GeneralRe: How to delete record from DataGrid control VB Pin
rizaky201120-Dec-11 19:12
rizaky201120-Dec-11 19:12 
GeneralRe: How to delete record from DataGrid control VB Pin
Dave Kreskowiak21-Dec-11 1:38
mveDave Kreskowiak21-Dec-11 1:38 
AnswerRe: How to delete record from DataGrid control VB Pin
qyasn20-Dec-11 23:24
qyasn20-Dec-11 23:24 
QuestionOracle forms 10g Pin
Member 380338516-Dec-11 21:06
Member 380338516-Dec-11 21:06 
AnswerRe: Oracle forms 10g Pin
Dave Kreskowiak17-Dec-11 3:33
mveDave Kreskowiak17-Dec-11 3:33 
QuestionSaving rtf-file Pin
jtpaa15-Dec-11 20:00
jtpaa15-Dec-11 20:00 
QuestionRe: Saving rtf-file Pin
Framework .l.15-Dec-11 20:31
Framework .l.15-Dec-11 20:31 
AnswerRe: Saving rtf-file Pin
jtpaa15-Dec-11 20:35
jtpaa15-Dec-11 20:35 
GeneralRe: Saving rtf-file Pin
Framework .l.15-Dec-11 22:02
Framework .l.15-Dec-11 22:02 
GeneralRe: Saving rtf-file Pin
Richard MacCutchan15-Dec-11 22:34
mveRichard MacCutchan15-Dec-11 22:34 
GeneralRe: Saving rtf-file Pin
jtpaa15-Dec-11 22:52
jtpaa15-Dec-11 22:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.