Note that there are some explanatory texts on larger screens.

plurals
  1. POTake value From listbox to label in C#
    text
    copied!<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/12243118/take-value-from-query-to-label-in-c-sharp">Take value from query to label in C#</a> </p> </blockquote> <p>Im newbie in C#</p> <p>I have 3 table in Ms SQL.. tbl_staff, tbl_logs and tbl_department</p> <p>In Windows form, I have one list box and two label. List box will display userID in tbl_logs. </p> <p>When the user chooses from the list box, the label will change a value and display the name and department in same form.</p> <p>The problem is, how can i paste a value from list box to label based on query?</p> <p>This is my SQL query</p> <pre><code>SELECT tbl_staff.userID, tbl_staff.staffName,tbl_department.department FROM tbl_staff,tbl_logs,tbl_department WHERE tbl_staff.userID = tbl_logs.userID and tbl_staff.idDepartment = tbl_department.idDepartment; </code></pre> <p>How to do in c# and paste value to label? Below is my current code</p> <pre><code>SqlConnection openCon = new SqlConnection(connString); openCon.Open(); SqlCommand queryChangeName = new SqlCommand(); int index = listStaff.SelectedIndex; DataSet ds = new DataSet(); ds.Clear(); SqlDataAdapter adapter = new SqlDataAdapter("SELECT tbl_staff.userID, tbl_staff.staffName,tbl_department.department FROM tbl_staff,tbl_logs,tbl_department WHERE tbl_staff.userID = tbl_logs." + listStaff.SelectedValue + " and tbl_staff.idDepartment = tbl_department.idDepartment";", openCon); </code></pre> <p>I dont have any idea to do, hope someone can help me to resolve this problem. And sorry for bad english.</p> <p>Thanks alot ;)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload