DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • How to Build a Full-Stack App With Next.js, Prisma, Postgres, and Fastify
  • A Step-by-Step Guide to Implementing Columnar Tables in SQL Server
  • From Open SQL to CDS Views: Rewriting SAP Data Access for Performance at Scale
  • Beyond Partitioning and Z-Order: A Deep Dive into Liquid Clustering for Unity Catalog Managed Tables

Trending

  • How to Keep AI Agents From Going Rogue Using Docker Sandbox
  • Rebuilding Elasticsearch Under Load: Unsafe Watermarks and a Sampling Blind Spot
  • Batching Strategies: Throughput vs Latency in Practice
  • Data Integration Landscape 2026: Event Streaming, API, and Batch in the Era of Agentic AI

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Data Engineering
  3. Data
  4. Displaying SQL Data in a Text Box Using C# [Code Snippet]

Displaying SQL Data in a Text Box Using C# [Code Snippet]

Here's a quick and easy way to put SQL database info into a text box when using C#.

By 
Arun kumar
·
Jun. 29, 16 · Code Snippet
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
28.2K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace RetrieveData {
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            }
        private void button1_Click(object sender, EventArgs e)
        {
            bool temp = false;
            SqlConnection con = new SqlConnection("server=arun\\SQLEXPRESS;database=pan;Trusted_Connection=True");
            con.Open();
            SqlCommand cmd = new SqlCommand("select * from Table2 where first='" + textBox1.Text.Trim() + "'", con);
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                textBox2.Text = dr.GetString(1);
                textBox3.Text = dr.GetString(2);
                temp = true;
                }
            if (temp == false)
            MessageBox.Show("not found");
            con.Close();
            }
        }
    }

Related Refcard:

C# Development

Snippet (programming) Data (computing) sql

Opinions expressed by DZone contributors are their own.

Related

  • How to Build a Full-Stack App With Next.js, Prisma, Postgres, and Fastify
  • A Step-by-Step Guide to Implementing Columnar Tables in SQL Server
  • From Open SQL to CDS Views: Rewriting SAP Data Access for Performance at Scale
  • Beyond Partitioning and Z-Order: A Deep Dive into Liquid Clustering for Unity Catalog Managed Tables

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook