-
Sep 14th, 2021, 12:50 PM
#1
Thread Starter
Lively Member
Datagridview data from SQL database
Hi,
I have an issue at run time:
Error message:
'Units' is not declared. It may be inaccessible due to its protection level. RCMS
'Units' is a header on the datagridview (DsUnitsUp), therefore,
if the propertyID = DgUnitsUp.Rows(i).Cells(0).Value and units = DgUnitsUp.Rows(i).Cells(1).Value, then show the value on the combobox.
E.g.
PropertyID = 1
Units = A1 , A2, A3
Flattype = One bedroom, One bedroom and three bedroom.
Therefore, Property 1 has 3 units, A1 = one bedroom, A2 = One bedroom and A3 = Three bedroom.
So, on the datagridview
Code:
PropertyID Units Flattype (this is a combobox)
1 A1 One bedroom
1 A2 One bedroom
1 A3 Three bedroom
PropertyID & units are bounded while flattype is unbounded.
Code:
'TODO: This line of code loads data into the 'DsUnitdetails.vwunitdetails' table. You can move, or remove it, as needed.
Me.VwunitdetailsTableAdapter.Fill(Me.DsUnitdetails.vwunitdetails, TxtPropertyIDClick.Text)
'Upload data the unbounded combobox to the datagridview in SQL
con.Open()
For i As Integer = 0 To DgUnitsUp.Rows.Count - 1
Dim cmd As New SqlCommand("Select flattype from vwunitdetails where propertyid = '" & DgUnitsUp.Rows(i).Cells(0).Value & "'" And Units = DgUnitsUp.Rows(i).Cells(1).Value & "'", con)
Dim myreader As SqlClient.SqlDataReader = cmd.ExecuteReader
FlatType.Items.Clear()
While myreader.Read
FlatType.Items.Add(myreader("FlatType"))
End While
Next
con.Close()
Thanks
Last edited by dr225; Sep 14th, 2021 at 01:59 PM.
-
Sep 14th, 2021, 01:59 PM
#2
Thread Starter
Lively Member
Re: Datagridview data from SQL database
Tried
Code:
Dim cmd As New SqlCommand("Select flattype from vwunitdetails where propertyid = '" & DgUnitsUp.Rows(i).Cells(0).Value & "' And Units '" = DgUnitsUp.Rows(i).Cells(1).Value & "'", con)
No error but the where clause is not populating the respective flattype
-
Sep 14th, 2021, 02:00 PM
#3
Re: Datagridview data from SQL database
You haven't got the syntax right there, this section:
Code:
DgUnitsUp.Rows(i).Cells(0).Value & "'" And Units = DgUnitsUp.Rows(i).Cells(1).Value
...should be:
Code:
DgUnitsUp.Rows(i).Cells(0).Value & "' And Units = '" & DgUnitsUp.Rows(i).Cells(1).Value
-
Sep 14th, 2021, 02:44 PM
#4
Thread Starter
Lively Member
Re: Datagridview data from SQL database
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|