TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Subham Dasgupta
NA
1
1.1k
login form
Jun 28 2015 3:06 AM
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Class_Project
{
public partial class Form1 : Form
{
public string id, pwd;
SqlConnection cn = new SqlConnection();
public void con()
{
cn.ConnectionString = "Data Source=SUBHAM-PC;Initial Catalog=hm;User id=sa;Password=subham";
}
public Form1()
{
InitializeComponent();
}
private void cmdLogin_Click(object sender, EventArgs e)
{
id = textBox1.Text;
pwd = textBox2.Text;
if (id != "")
{
con();
cn.Open();
try
{
string qry = "select Username,Password from login where Username = @uid and Password = @pass";
SqlCommand cmd = new SqlCommand(qry, cn);
cmd.Parameters.Add(new SqlParameter("@uid", id));
cmd.Parameters.Add(new SqlParameter("@pass", pwd));
SqlDataReader rdr = cmd.ExecuteReader();
if (rdr.Read() == true)
{
this.Hide();
form2 f2 = new form2();
f2.Show();
}
else
{
MessageBox.Show("Invalid login.Try Again", "login", MessageBoxButtons.OK, MessageBoxIcon.Warning);
textBox1.Text = "";
textBox2.Text = "";
textBox1.Focus();
}
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message, "System", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message, "System", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
cn.Close();
}
}
else
{
MessageBox.Show("Input Id and Password", "Login", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void cmdCancel_Click(object sender, EventArgs e)
{
Close();
}
}
}
the coding is not working....
Reply
Answers (
2
)
How to add listbox selected item to textbox?
Putting an URL together in .NET 2