Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Reading single value from SQL

$
0
0

Hallo

Hope somebody can assist, I can get the SQL data into a datagrid, but for some reason I cannot figure out how to get this value into a simple variable or textbox, I do a lookup in a table and there will always just be one value.

Only trying to get the Chute Nr into a text box..

           try
            {
                conn.Open();
                cmd = new SqlCommand("SELECT ChuteNr FROM [STOREDETAILS] where StoreBarcode like @Barcode", conn);
                cmd.Parameters.AddWithValue("@Barcode", GetBoxCode().ToString());

                sda = new SqlDataAdapter(cmd);
                dt = new DataTable();

                sda.Fill(dt);

                this.dgSQLData.DataSource = dt;
                this.txtSideCode.Text = dt[ "ChuteNr" ].ToString();
                RowCount = this.dgSQLData.RowCount;
                StatusBits[0] = false;
                this.txtSQLStatusBar.Text = "Searching Data";
            }
            catch (Exception ex)
            {
                StatusBits[0] = true;
                MessageBox.Show(ex.ToString());
                this.txtSQLStatusBar.Text = "SQL Connection Error reading Code";
            }
            finally
            {
                conn.Close();
                RowCount = RowCount + 1;
                this.txtRecordCount.Text = Convert.ToString(RowCount);
            }


labjac


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>