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
Qing Ryder
NA
202
17.4k
Error in login form
Oct 20 2017 10:42 AM
am trying to create a login form using sql and when the application runs, it crashes at
da.Fill(dt);
public
partial
class
Form1 : Form
{
SqlConnection con =
new
SqlConnection();
public
Form1()
{
SqlConnection con =
new
SqlConnection();
con.ConnectionString = @
"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Xavier\Documents\Data.mdf;Integrated Security=True"
;
InitializeComponent();
}
private
void
pictureBox4_Click(
object
sender, EventArgs e)
{
SqlConnection con =
new
SqlConnection();
con.ConnectionString = @
"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Xavier\Documents\Data.mdf;Integrated Security=True"
;
con.Open();
string
Username = textBox1.Text;
string
Password = textBox2.Text;
SqlCommand cmd =
new
SqlCommand(
"select userid,password from login where Username='"
+ textBox1.Text +
"'and Password='"
+ textBox2.Text +
"'"
, con);
SqlDataAdapter da =
new
SqlDataAdapter(cmd);
DataTable dt =
new
DataTable();
da.Fill(dt);
if
(dt.Rows.Count > 0)
{
this
.Hide();
Form2 f2 =
new
Form2();
f2.Show();
}
else
{
MessageBox.Show(
"Invalid Login Credentials!"
);
}
}
}
}
Reply
Answers (
2
)
C# (Student Questions)
Unable to get excel file data in gridview please help me ...