a SqlDataAdapter needs an Open() SqlConnection and after the data is in the dataset the SqlConnection needs to be Closed()
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;
public partial class sigin_in : System.Web.UI.Page
{
string connectToDB = "Data Source=KRISHN-PC;Initial Catalog=sign;Persist Security Info=True;User ID=sa;Password=***********";
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(connectToDB);
string myQuery = string.Format("select from login where userid = '{0}' and password = '{1}'", TextBox1.Text, TextBox2.Text);
SqlDataAdapter obj = new SqlDataAdapter(myQuery, con);
try
{
con.Open()
DataSet a = new DataSet();
obj.Fill(a);
if (a.Tables[0].Rows.Count > 0)
{
Response.Redirect("home.aspx");
}
else
{
Label.Text = " wrong pswd";
}
}
catch (Exception err)
{
}
finally
{
if (null != con && con.Connection.State == ConnectionState.Open)
con.Close();
}
}
}