how to use sqldatareader in vb.net +windows

Posted by Shanky11 under VB.NET on 3/2/2013 | Points: 10 | Views : 1027 | Status : [Member] | Replies : 1
on edit btn i have to fill all text boxes with pre existing data in textbox
how can i read value from sql datareader object




Responses

Posted by: Satyapriyanayak on: 3/2/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Dropdownlist_click_data_in_textbox
{
public partial class WebForm1 : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string str;
SqlCommand com;
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(strConnString);

if (!IsPostBack)
{
con.Open();
str = "select * from employee where id =1";
com = new SqlCommand(str, con);
SqlDataReader reader = com.ExecuteReader();
while (reader.Read())
{
TextBox1.Text = reader["empname"].ToString();
TextBox2.Text = reader["empaddress"].ToString();
TextBox3.Text = reader["sal"].ToString();
}
reader.Close();
con.Close();
}
}
}
}


If this post helps you mark it as answer
Thanks

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response