How I show data in textbox (data fetch from database) ?
How I show data in textbox (data fetch from database) ?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Salman MushtaqPosted Jan 1, 2014, 5:11 AM
And this code that i attached not working
Satyapriya NayakPosted Jan 1, 2014, 2:54 AM
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 Show
{
public partial class Form1 : Form
{
SqlConnection con = new SqlConnection(@"server = HOME-SAT/SQLEXPRESS;data source = .; initial catalog = test; user id=sa;pwd =pintu ;integrated security = SSPI");
SqlCommand com=new SqlCommand();
string str;
public Form1()
{
InitializeComponent();
}
private void btnlogin_Click(object sender, EventArgs e)
{
if (TextBox_user_name.Text == "" || TextBox_password.Text == "")
{
MessageBox.Show("Please enter User ID or Password");
TextBox_user_name.Text = "";
TextBox_password.Text = "";
}
else
{
con.Open();
str = "select * from login where username='" + TextBox_user_name.Text.Trim() + "' and password='" + TextBox_password.Text.Trim() + "'";
com = new SqlCommand(str, con);
SqlDataReader reader = com.ExecuteReader();
while (reader.Read())
{
txt_id.Text = (reader["id"].ToString());
}
reader.Close();
con.Close();
}
}
}
}
Salman MushtaqPosted Jan 1, 2014, 1:13 AM
Now i faced a new problem the description is that i have 2 records in database. I write username and password and click on button and messagebox occur that show Id against that username and password , it is ok but when i write username and password of second record it cannot show any Id against that username and password , so now please tell me how the problem is resolved ?
Satyapriya NayakPosted Dec 31, 2013, 10:03 AM
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 Displaying_Data
{
public partial class _Default : 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);
con.Open();
str = "select * from emp";
com = new SqlCommand(str, con);
SqlDataReader reader = com.ExecuteReader();
reader.Read();
textbox1.Text = reader["Name"].ToString();
}
}
}