Reputation: 199
I want to display records in textbox
and put only some records in a datagridview
.
Store procedure code
SELECT sh.SchoolYear,
sh.Levels,sh.Section, sh.DateEnrolled as LatestDate ,
SI.StudentID,SI.Surname,SI.FirstName,SI.MiddleName, SI.StudAddress ,
SI.BirthDay,SI.Gender, SI.Nationality, SI.BirthPlace,
SI.TelNum,SI.SchoolWhereGraduated ,
SI.DatesWhenGraduated, SI.SchoolLastAttended,
SI.SchoolAddress, SI.Note,SI.StudImage,
PI.Father_FirstName,PI.Father_LastName,
PI.Father_MI,PI.Father_Occupation,
PI.Father_TelNUm, PI.Mother_FirstName, PI.Mother_LastName,
PI.Mother_MI,PI.Mother_Occupation,PI.Mother_TelNum,
PI.Contact_FirstName,PI.Contact_LastName,PI.Contact_MI,
PI.Contact_Mobile,PI.Contact_TelNum,PI.Contact_Address
FROM StudentInformation SI
JOIN StudentHistory SH
ON SI.StudentID = SH.StudentID
JOIN ParentInformation PI
ON PI.ParentID = SI.ParentID
WHERE si.StudentID = @studID
ORDER BY DateEnrolled DESC
vb.net code
cmd = New SqlCommand("uspstudents", cn)
cmd.Parameters.AddWithValue("@studID", frmView.dgv1.SelectedCells(0).Value)
cmd.CommandType = CommandType.StoredProcedure
da.SelectCommand = cmd
da.Fill(dt)
cboSchoolYear.Text = dt.Rows(0)("SchoolYear").ToString
cboSection.Text = dt.Rows(0).Item("Section").ToString
cboGradeLevel.Text = dt.Rows(0).Item("levels").ToString
dtpEnrollment.Text = dt.Rows(0).Item("LatestDate").ToString
txtStudLN.Text = dt.Rows(0)("SurName").ToString
txtStudFN.Text = dt.Rows(0)("FirstName").ToString
txtStudMN.Text = dt.Rows(0)("MiddleName").ToString
txtAddress.Text = dt.Rows(0)("StudAddress").ToString
dtpBirthday.Text = dt.Rows(0)("birthday").ToString
cboNationality.Text = dt.Rows(0)("Nationality").ToString
txtPlaceOfBirth.Text = dt.Rows(0)("BirthPlace").ToString
txtStudentCP.Text = dt.Rows(0)("telnum").ToString
txtSWG.Text = dt.Rows(0)("schoolWhereGraduated").ToString
dtpDWG.Text = dt.Rows(0)("datesWhenGraduated").ToString
txtSLA.Text = dt.Rows(0)("schoolLastAttended").ToString
txtSchoolAddress.Text = dt.Rows(0)("SchoolAddress").ToString
txtNote.Text = dt.Rows(0)("Note").ToString
txtFatherGN.Text = dt.Rows(0)("Father_FirstName").ToString
txtFatherMI.Text = dt.Rows(0)("Father_MI").ToString
txtFatherLN.Text = dt.Rows(0)("Father_Lastname").ToString
txtFatherOccupation.Text = dt.Rows(0)("Father_Occupation").ToString
txtFatherCP.Text = dt.Rows(0)("Father_telnum").ToString
txtMotherGN.Text = dt.Rows(0)("Mother_FirstName").ToString
txtMotherLN.Text = dt.Rows(0)("Mother_LastName").ToString
txtMotherMI.Text = dt.Rows(0)("Mother_MI").ToString
txtMotherOccupation.Text = dt.Rows(0)("Mother_Occupation").ToString
txtMotherCP.Text = dt.Rows(0)("Mother_telNum").ToString
txtContactGN.Text = dt.Rows(0)("Contact_FirstName").ToString
txtContactLN.Text = dt.Rows(0)("Contact_LastName").ToString
txtContactMI.Text = dt.Rows(0)("Contact_MI").ToString
txtContactAddress.Text = dt.Rows(0)("Contact_Address").ToString
txtContactCP.Text = dt.Rows(0)("Contact_Mobile").ToString
txtContactTelNum.Text = dt.Rows(0)("Contact_telnum").ToString
Displaying of data in a textbox
works well but the problem is in the datagridview
. What i have tried is to put this code inside my vb.net code
dgvHistory.DataSource = dt
But it displays all the data in my records, what i want is to display only the schoolyear
,section
and levels
in a datagridview
. Can someone help me to solve this problem. Thanks
Upvotes: 1
Views: 48
Reputation: 6656
You need to create the columns manually for the DataGridView. something like this -
dgvHistory.ColumnCount = 3
dgvHistory.AutoGenerateColumns = False
dgvHistory.Columns(0).Name = "SchoolYear"
dgvHistory.Columns(0).DataPropertyName = "schoolyear"
dgvHistory.Columns(1).Name = "Section"
dgvHistory.Columns(1).DataPropertyName = "Section"
dgvHistory.Columns(2).Name = "Levels"
dgvHistory.Columns(2).DataPropertyName = "levels"
dgvHistory.DataSource = dt
Upvotes: 1