Note that there are some explanatory texts on larger screens.

plurals
  1. POReading Querying database with a Parameter to Display Results in Text Boxes
    primarykey
    data
    text
    <p>I'm currently building a database font end and I'm currently stuck. I'm trying to take the List item of a datasourced drop down list and use that as a parameter in a SQL query. I then wan each column from those results to be displayed in a text box. Here's some code!</p> <p>On button event:</p> <pre><code>protected void ButtonAsset_Click(object sender, EventArgs e) { ExecuteSelect(DropDownListAsset.Selecteditem.Text); } </code></pre> <p>Getting the Connection String: </p> <pre><code> public string GetConnectionStringMyConn() { return System.Configuration.ConfigurationManager.ConnectionStrings["my_conn"].ConnectionString; } </code></pre> <p>The Select method:</p> <pre><code> private void ExecuteSelect(string Aname) { SqlConnection connection = new SqlConnection(GetConnectionStringMyConn()); using (var command = connection.CreateCommand()) { command.CommandText = "Select tblAssets.AssetID, tblAssets.Domain, tsysOS.OSname, tblAssets.SP," + "tblAssets.Memory, tblAssets.Processor, tblAssetCustom.Manufacturer, tblAssetCustom.Model)" + "FROM tblAssets" + "INNER JOIN tblAssetsCustom ON tblAssets.AssetID = tblAssetCustom.AssetID " + "INNER JOIN tsysOS ON tblAssets.OScode = tsysOS.OScode " + "WHERE tblAssets.AssetName = @AssetName"; connection.Open(); SqlParameter[] Aparam = new SqlParameter[1]; Aparam[0] = new SqlParameter("@AssetName", SqlDbType.NVarChar); Aparam[0].Value = Aname; using (var reader = command.ExecuteReader()) { while (reader.Read()) TextBoxAssetID.Text = reader["AssetID"].ToString(); TextBoxDomain.Text = reader["Domain"].ToString(); TextBoxOS.Text = reader["OSname"].ToString(); TextBoxSP.Text = reader["SP"].ToString(); TextBoxMemory.Text = reader["Memory"].ToString(); TextBoxProcessor.Text = reader["Processor"].ToString(); TextBoxManufacturer.Text = reader["Manufacturer"].ToString(); TextBoxModel.Text = reader["Model"].ToString(); } connection.Close(); } } </code></pre> <p>Any help would be much appreciated! I keep getting syntax errors on using (var reader = command.ExecuteReader()) and I cannot understand why. I've been using this <a href="https://stackoverflow.com/questions/6341819/get-sql-data-and-show-it-in-a-text-box">Get SQL data And show it in a text box?</a> for the reader</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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