check in database !!
how can i authenticate that the given data doesn't exist in 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.
Riddhi ValechaPosted May 13, 2013, 3:49 AM
What are you exactly trying to check?? Login Page - to check whether the user exists or not ??
Or some sort of data??
Please explain your question properly.
Jignesh TrivediPosted May 12, 2013, 11:43 PM
you can also use "IF Exist" instead of count.
string Name = 'Jignesh';
string query = "IF EXISTS (SELECT 1 FROM Tables1 WHERE NAME = '" + Name + "') return 1 ELSE return 0";
bool TableExists;
using (SqlConnection connection = new SqlConnection(connectionString))
{
using (SqlCommand command = new SqlCommand(query))
{
command.CommandType = CommandType.Text;
connection.Open();
command.Connection = connection;
bool DataExists = (bool)(command.ExecuteScalar());
connection.Close();
}
}
hope this will help you.
Satyapriya NayakPosted May 12, 2013, 2:15 PM
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 Check_Data_dosenot_exist_database
{
public partial class _Default : System.Web.UI.Page
{
string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand com;
string str;
protected void btn_check_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(connStr);
con.Open();
str = "select count(*)from employee where ename='" + txtUserName.Text + "'";
com = new SqlCommand(str, con);
int count = Convert.ToInt32(com.ExecuteScalar());
if (count > 0)
{
lblMessage.Text = "username exist";
}
else
{
lblMessage.Text = "username doesnot exist";
}
}
}
}