add an ID from an from an combobox in buttun click event
-
hello to everyone I'm trying to store an ID of a person from a table which is related to another so I wrote a peace of code that takes the names of persons from that table and expandes them on a combobox but when I click on a Save button it does not take the ID of a person to store it on a table which is related. Here is my code: Private Sub frmXhirojare_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim ds As New DataSet Dim conn As SqlConnection = New SqlConnection("Data Source=.;Initial Catalog=dbHyrjaXhirove;Integrated Security=True") Dim selection As String = "SELECT PartneriID, Emri FROM tblPartneret" Dim dataadapteri As SqlDataAdapter = New SqlDataAdapter(selection, conn) dataadapteri.MissingSchemaAction = MissingSchemaAction.AddWithKey dataadapteri.Fill(ds, "tblXhiro") ComboBox1.DataSource = ds.Tables("tblXhiro") ComboBox1.ValueMember = "PartneriID" ComboBox1.DisplayMember = "Emri" End Sub I would be thankful to everyone who takes a minute from his time to explain it to me why when I click to the Save button it does not take the PartneriID in this case and store it on related table.
Qendro
-
hello to everyone I'm trying to store an ID of a person from a table which is related to another so I wrote a peace of code that takes the names of persons from that table and expandes them on a combobox but when I click on a Save button it does not take the ID of a person to store it on a table which is related. Here is my code: Private Sub frmXhirojare_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim ds As New DataSet Dim conn As SqlConnection = New SqlConnection("Data Source=.;Initial Catalog=dbHyrjaXhirove;Integrated Security=True") Dim selection As String = "SELECT PartneriID, Emri FROM tblPartneret" Dim dataadapteri As SqlDataAdapter = New SqlDataAdapter(selection, conn) dataadapteri.MissingSchemaAction = MissingSchemaAction.AddWithKey dataadapteri.Fill(ds, "tblXhiro") ComboBox1.DataSource = ds.Tables("tblXhiro") ComboBox1.ValueMember = "PartneriID" ComboBox1.DisplayMember = "Emri" End Sub I would be thankful to everyone who takes a minute from his time to explain it to me why when I click to the Save button it does not take the PartneriID in this case and store it on related table.
Qendro
ComboBox1.Value
should contain the person Id.Steve Jowett ------------------------- Real programmers don't comment their code. If it was hard to write, it should be hard to read.
-
ComboBox1.Value
should contain the person Id.Steve Jowett ------------------------- Real programmers don't comment their code. If it was hard to write, it should be hard to read.
Could You be more specific and tell me where to write Combobox1.Value because in my code I wrote Combobox1.ValueMember = "PartneriID" which I think is the appropriate thing in this case.My problem is that when I click on the Save button it saves all the values through the parameters exept the PersoniID which is represeted by this combobox. Thank You for your reply and I would be thankful if You put me in a correct road with this problem. :)
Qendro
-
Could You be more specific and tell me where to write Combobox1.Value because in my code I wrote Combobox1.ValueMember = "PartneriID" which I think is the appropriate thing in this case.My problem is that when I click on the Save button it saves all the values through the parameters exept the PersoniID which is represeted by this combobox. Thank You for your reply and I would be thankful if You put me in a correct road with this problem. :)
Qendro
ValueMember sets where to get the value from. Value is the value that was set. I think you need to do some reading on VB.NET, this is pretty straightforward stuff.
Christian Graus Driven to the arms of OSX by Vista.