Hi!
I am trying to display a record in my datagridview based on the value selected from a combobox. I tried the code below using SQL Management studio and it works perfectly.but once I do it in vb.net I dont get any display in my datagridview.Code:SELECT DISTINCT tblSubjects.SubjectName, tblSubjects.YearLevel FROM tblsubjects INNER JOIN tblSection ON tblSubjects.Yearlevel=tblsection.yearlevel WHERE dbo.tblSubjects.YearLevel = 'LC7'
Here's what I want to achieve....my combobox contains list of class section names, I have also two databindings for my yearlevel and dept on a textboxes.
I want to just display in my datagridview all the subjects belonging to a certain yearlevel in the first column and an empty 2nd column so that user can type/assign teachers who teaches the subjects displayed and then click on a save button to update/save all the records to another table name as teachersload.
I am supposed to display the subjects and beside it is a combobox in datagridview displaying all the teachers name from teachersfile table so that i get to choose from the list but then its been a big problem for me to do it. Hope someone can help me out here....
Thanks in advance...
BTW..here is what my code for now. No saving yet.Code:Imports System.Data.SqlClient Public Class frmLoading Private cnn As New SqlConnection(My.Settings.MyConnectionString) Private Sub frmLoading_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If cnn.State = ConnectionState.Closed Then cnn.Open() 'DISPLAY YEAR LEVEL IN CBOYEARLEVEL Using cmdSectionName As New SqlCommand("SELECT SectionName, YearLevel, Dept " & _ "FROM tblSection " & _ "WHERE Dept LIKE 'HS%' " & _ "ORDER BY YearLevel ASC", cnn) Using reader As SqlDataReader = cmdSectionName.ExecuteReader() Dim Table As New DataTable Table.Load(reader) cboSectionName.DataSource = Table cboSectionName.DisplayMember = "SectionName" txtYearLevel.DataBindings.Add("text", Table, "YearLevel") txtDept.DataBindings.Add("Text", Table, "Dept") End Using End Using Using command As New SqlCommand("SELECT DISTINCT tblSubjects.SubjectName, tblSubjects.YearLevel " & _ "FROM tblsubjects INNER JOIN " & _ "tblSection ON tblSubjects.Yearlevel=tblsection.yearlevel " & _ "WHERE tblSubjects.YearLevel = '@Year' ", cnn) With command.Parameters .AddWithValue("@Year", Me.txtYearLevel.Text.Trim) End With Using reader1 As SqlDataReader = command.ExecuteReader() Dim table1 As New DataTable table1.Load(reader1) dtgLoad.DataSource = table1 End Using End Using 'End Using End Sub End Class




Reply With Quote