TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
vikas m
NA
3
1.1k
code to fetch data from database and display all records
Jul 31 2014 11:02 AM
hi,
i have written a code to fetch data from database and display it in a textbox
but the problem is that it displays only the last value
what modification should i do to display all values in the textbox one by one
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 sample2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
db();
}
private void Form1_Load(object sender, EventArgs e)
{
}
public void db()
{
SqlConnection con = new SqlConnection("Data Source=xxxx;Initial Catalog=temp1;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("Select * from t1",con);
SqlDataReader reader = cmd.ExecuteReader();
while(reader.Read())
{
textBox1.Text = reader.GetValue(0).ToString();
}
con.Close();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
}
}
Reply
Answers (
3
)
how to delete selected row of datagrideview using checkboxes
Winforms desktop development