Click here to Skip to main content
15,898,222 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: vs 2005 , vb.net Pin
Rupesh Kumar Swami4-Feb-09 1:35
Rupesh Kumar Swami4-Feb-09 1:35 
GeneralRe: vs 2005 , vb.net Pin
mahalakshmi4211-Feb-09 23:30
mahalakshmi4211-Feb-09 23:30 
Questionvb6 - how could i get address as i open a folder Pin
meissey3-Feb-09 22:15
meissey3-Feb-09 22:15 
AnswerRe: vb6 - how could i get address as i open a folder Pin
Rupesh Kumar Swami4-Feb-09 0:01
Rupesh Kumar Swami4-Feb-09 0:01 
QuestionHow can I change the script of the font for a form if it is not changing? Pin
JUNEYT3-Feb-09 21:42
JUNEYT3-Feb-09 21:42 
AnswerRe: How can I change the script of the font for a form if it is not changing? Pin
StuBaum4-Feb-09 17:08
StuBaum4-Feb-09 17:08 
QuestionThe Specified module could not found.( Exception from HRESULT Pin
tsanthosh3-Feb-09 21:18
tsanthosh3-Feb-09 21:18 
QuestionBind a Combobox in VB 2008 Pin
Jaco Muller3-Feb-09 20:09
Jaco Muller3-Feb-09 20:09 
I have been programming with VB6 for many years and I am now in the process of “upgrading” to VB2008. I want to do all my work with code and not with data controls. (See my attached code so far). This is a useless sample just to get my head around a few things.
1. In the scores group on my form, I have 3 textboxes binded to my “BindingManagerBase” I can now move up and done both tables. I want to add “Delete”, “Add” and “Edit” functionality for the Scores table. Instead of manually looking up the StudentID, I want to replace the textbox with a Combobox. So I want to see the student’s “FirstName” from the students table in the combo box, and then link the StudentID from the Student Table to the StudentID in the TestScores table. (I have done it many times with VB6, but how do I do it in VB2008.



This is my tables and my code.

Table Name: Students
StudentID FirstName LastName
1 Amy Anderson
2 Bob Baker
3 Cindy Carter
4 Donald Dorph

Table Name: TestScores
StudentID TestNumber Score
1 1 98
1 2 94
2 1 74
3 2 65

' Data adapter for the Students table.
Dim m_daStudents As New OleDbDataAdapter( _
"SELECT Students.StudentID, Students.FirstName, Students.LastName " & _
"FROM Students", _
"PROVIDER=MSDataShape;" & _
"Data PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source='Student Scores.mdb';" & _
"Persist Security " & _
"Info=False")
' Data adapter for the TestScores table.
Dim m_daTestScores As New OleDbDataAdapter( _
"SELECT TestScores.StudentID, TestScores.TestNumber, TestScores.Score " & _
"FROM TestScores", _
"PROVIDER=MSDataShape;" & _
"Data PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source='Student Scores.mdb';" & _
"Persist Security " & _
"Info=False")
' The DataSet.
Dim m_DataSet As New DataSet("Student Scores")
' Declare a binding manager field
Public bm_Students As BindingManagerBase
Public bm_TestScores As BindingManagerBase

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Load the Students table.
m_daStudents.Fill(m_DataSet, "Students")
' Load the TestScores table.
m_daTestScores.Fill(m_DataSet, "TestScores")
' Get the DataTable objects.
Dim dt_students As DataTable = m_DataSet.Tables("Students")
Dim dt_testscores As DataTable = m_DataSet.Tables("TestScores")

' Get DataColumn objects we will need.
Dim col_students_studentid As DataColumn = _
dt_students.Columns("StudentId")
Dim col_testscores_studentid As DataColumn = _
dt_testscores.Columns("StudentId")
Dim col_testscores_testnumber As DataColumn = _
dt_testscores.Columns("TestNumber")

' Define the primary keys.
Dim students_keys() As DataColumn = _
{col_students_studentid}
dt_students.PrimaryKey = students_keys

Dim testscores_keys() As DataColumn = _
{col_testscores_studentid, col_testscores_testnumber}
dt_testscores.PrimaryKey = testscores_keys

' Make a foreign key constraint.
Dim fk_studentid As New ForeignKeyConstraint( _
col_students_studentid, col_testscores_studentid)
dt_testscores.Constraints.Add(fk_studentid)

' Bind to textboxes for Students table
txtStudentID.DataBindings.Add("text", m_DataSet, "Students.StudentID")
txtFirstName.DataBindings.Add("text", m_DataSet, "Students.FirstName")
txtLastName.DataBindings.Add("text", m_DataSet, "Students.LastName")

' Bind to textboxes for TestScore table
txtTestScores1.DataBindings.Add("text", m_DataSet, "TestScores.StudentID")
txtTestScores2.DataBindings.Add("text", m_DataSet, "TestScores.TestNumber")
txtTestScores3.DataBindings.Add("text", m_DataSet, "TestScores.Score")

' Bind to datagrid for TestScore table
DataGridView1.DataSource = m_DataSet
DataGridView1.DataMember = "TestScores"

bm_Students = BindingContext(m_DataSet, "Students")
bm_Students.Position = 0
bm_TestScores = BindingContext(m_DataSet, "TestScores")
bm_TestScores.Position = 0

End Sub
AnswerRe: Bind a Combobox in VB 2008 Pin
Jay Royall4-Feb-09 5:56
Jay Royall4-Feb-09 5:56 
GeneralRe: Bind a Combobox in VB 2008 Pin
Jaco Muller4-Feb-09 11:20
Jaco Muller4-Feb-09 11:20 
GeneralRe: Bind a Combobox in VB 2008 Pin
Jay Royall4-Feb-09 22:37
Jay Royall4-Feb-09 22:37 
GeneralRe: Bind a Combobox in VB 2008 Pin
Jaco Muller4-Feb-09 23:04
Jaco Muller4-Feb-09 23:04 
GeneralRe: Bind a Combobox in VB 2008 Pin
Jay Royall4-Feb-09 23:33
Jay Royall4-Feb-09 23:33 
GeneralRe: Bind a Combobox in VB 2008 Pin
Jaco Muller5-Feb-09 11:47
Jaco Muller5-Feb-09 11:47 
GeneralRe: Bind a Combobox in VB 2008 Pin
Jay Royall5-Feb-09 23:57
Jay Royall5-Feb-09 23:57 
GeneralRe: Bind a Combobox in VB 2008 Pin
Jaco Muller6-Feb-09 0:09
Jaco Muller6-Feb-09 0:09 
QuestionInvoking .Net DLL [modified] Pin
subramanyeswari3-Feb-09 18:55
subramanyeswari3-Feb-09 18:55 
AnswerRe: Invoking .Net DLL Pin
Christian Graus3-Feb-09 19:24
protectorChristian Graus3-Feb-09 19:24 
GeneralRe: Invoking .Net DLL Pin
subramanyeswari3-Feb-09 20:32
subramanyeswari3-Feb-09 20:32 
GeneralRe: Invoking .Net DLL Pin
Dave Kreskowiak4-Feb-09 2:24
mveDave Kreskowiak4-Feb-09 2:24 
QuestionTrap "Enter" key press Pin
moonshaddow3-Feb-09 16:38
moonshaddow3-Feb-09 16:38 
GeneralRe: Trap "Enter" key press Pin
Luc Pattyn3-Feb-09 17:35
sitebuilderLuc Pattyn3-Feb-09 17:35 
AnswerRe: Trap "Enter" key press Pin
EliottA3-Feb-09 18:08
EliottA3-Feb-09 18:08 
AnswerRe: Trap "Enter" key press Pin
Dave Kreskowiak3-Feb-09 18:16
mveDave Kreskowiak3-Feb-09 18:16 
AnswerRe: Trap "Enter" key press Pin
StuBaum4-Feb-09 17:17
StuBaum4-Feb-09 17:17 

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.