Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Satyapriya NayakRank #47 · 31.5K reputationPosted Dec 31, 2013, 5:03 AM EST
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();
}
}
}
Salman Mushtaq44 reputationPosted Dec 31, 2013, 8:13 PM EST
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 NayakRank #47 · 31.5K reputationPosted Dec 31, 2013, 9:54 PM EST
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 Mushtaq44 reputationPosted Jan 1, 2014, 12:11 AM EST
And this code that i attached not working