5 Replies - 1031 Views - Last Post: 15 October 2011 - 05:55 AM Rate Topic: -----

#1 hwkong1688  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 30-September 11

how to display another table field value on label1.text

Posted 15 October 2011 - 03:13 AM

hi,

let said, i click the row 2 on table1 datagridview1 then will display the total value on row 2 table2 to
label1.text

eg:
table 1 (da), datagridview1

Itemcode (data type number)
Description (data type Text)
quantity (data type number)


table 2 (da2), datagridview2

Itemcode (data type number)
Description (data type text)
Total (data type number)

see attachment.


how to write the code ?

anyone help much appreciated.

Attached image(s)

  • Attached Image
  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: how to display another table field value on label1.text

#2 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1819
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: how to display another table field value on label1.text

Posted 15 October 2011 - 03:36 AM

Since you know how to load the first table to grid, it now easy.... just get the value of the first column and use it to query your another value. Try it, just few lines of code, and if you have any problem, feel free to post it with updated code.
Was This Post Helpful? 0
  • +
  • -

#3 hwkong1688  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 30-September 11

Re: how to display another table field value on label1.text

Posted 15 October 2011 - 04:04 AM

thank you for reply, i know how to get the value from first column, but i don't know how to write the code for query to another value.

can you provide me simple example, thank you.
Was This Post Helpful? 0
  • +
  • -

#4 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1819
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: how to display another table field value on label1.text

Posted 15 October 2011 - 04:18 AM

Sure, you just need a WHERE clause, "select coulmnName from tableName where coumnName = " & selected
Just declare selected and assign it a value of column 0.
Was This Post Helpful? 0
  • +
  • -

#5 hwkong1688  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 30-September 11

Re: how to display another table field value on label1.text

Posted 15 October 2011 - 05:37 AM

why still cannot, something wrong with my code??

no error

only can get the first column 0 itemcode in table (da)

my code:
Private Sub DataGridView2_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView2.CellClick

Label4.Text = DataGridView2.CurrentRow.Cells("total").Value.ToString()

Dim com7 As New OleDbCommand
com7.Connection = conn1

com7.CommandText = "Select Total from da2 where total = " & Label4.Text
com7.ExecuteNonQuery()

End Sub


Was This Post Helpful? 0
  • +
  • -

#6 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1819
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: how to display another table field value on label1.text

Posted 15 October 2011 - 05:55 AM

Now you dont need to ExecuteNonQuery(), you need to ExecuteReader() and declare a variable of type SqlDataReader to get the value from it:
Dim dr As SqlDataReader = com7.ExecuteReader()
'now from dr, you have your variable by saying dr.Item("Total")

Note: your query is wrong. look at it, you select the same column where you check for condition, the condition should be the table ID like "WHERE ID = " &....
Also if your column is of varchar type, then you need a colon between them
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1