Impact of Gen-AI on IT Jobs - Growth Mindset Show
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
.NET
.NET Assemblies
.NET Core
.NET Standard
Active Directory
ADO.NET
Agile Development
AJAX
Alexa Skills
Algorithms in C#
Android
Angular
Architecture
ArcObject
Artificial Intelligence
ASP.NET
ASP.NET Core
Augmented Reality
Aurelia
AWS
Azure
Backbonejs
Big Data
BizTalk Server
Blockchain
Bootstrap
Bot Framework
Business
C#
C# Corner
C, C++, MFC
Career Advice
Chapters
CIO
Cloud
COBOL.NET
Coding Best Practices
Cognitive Services
COM Interop
Compact Framework
Cortana Development
Cryptocurrency
Cryptography
Crystal Reports
Current Affairs
Custom Controls
Cyber Security
Data Mining
Databases & DBA
Design Patterns & Practices
DevOps
DirectX
Dynamics CRM
Enterprise Development
Entity Framework
Error Zone
Exception Handling
Expression Studio
F#
Files, Directory, IO
Games Programming
GDI+
General
Generative Engine Optimization (GEO)
Google Cloud
Google Development
Graphics Design
Hardware
Hiring and Recruitment
HoloLens
How do I
HTML 5
Internet & Web
Internet of Things
Ionic
iOS
Java
Java and .NET
JavaScript
JQuery
JSON
JSP
Knockout
kotlin
Leadership
Learn .NET
LightSwitch
LINQ
Machine Learning
Microsoft 365
Microsoft Office
Microsoft Phone
Mobile Development
Multithreading
Nano Banana
NetBeans
Networking
Node.js
Office Development
OOP/OOD
Open Source
Operating Systems
Oracle
Outsourcing
Philosophy
PHP
Power BI
Printing in C#
Products
Progressive Web Apps
Project Management
Python
Q#
QlikView
R
React
Reports using C#
Robotics & Hardware
Ruby on Rails
Salesforce
Security
Servers
SharePoint
SignalR
Silverlight
Smart Devices
Software Testing
SQL Language
SQL Server
Startups
String in C#
Swift
TypeScript
Unity
UWP
Visual Basic .NET
Visual Studio
WCF
Wearables
Web Development
Web Services
Web3
Windows 10
Windows Controls
Windows Forms
Windows PowerShell
Windows Services
Workflow Foundation
WPF
Xamarin
XAML Standard
XML
XNA
XSharp
Register
Login
3
Answers
Help in the login
Hold On
7y
160
0
1
Others
Reply
I have a private method below
private
void
Login()
{
int
UserId;
UsersDataModel usersDataModel =
new
UsersDataModel();
using
(SqlConnection con = DBCS.GetConString())
{
string
UserName = username.Value.Trim();
string
Password = password.Value.Trim();
string
SchoolCode = lblSchoolCode.Text.Trim();
string
SchoolName = lblSchoolName.Text.Trim();
string
LastLogin = lblLastLoginDate.Text.Trim();
//UserId = Convert.ToInt32(hfUserID.Value.Trim());
con.Open();
SqlCommand cmd =
new
SqlCommand(
"Validate_User"
, con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue(
"@Username"
, UserName);
cmd.Parameters.AddWithValue(
"@Password"
, Password);
SqlDataAdapter da =
new
SqlDataAdapter(cmd);
DataTable dt =
new
DataTable();
da.Fill(dt);
RowCount = dt.Rows.Count;
for
(
int
i = 0; i < RowCount; i++)
{
UserName = dt.Rows[i][
"Username"
].ToString();
Password = dt.Rows[i][
"Password"
].ToString();
SchoolCode = dt.Rows[i][
"SchoolCode"
].ToString();
SchoolName = dt.Rows[i][
"SchoolName"
].ToString();
LastLogin = dt.Rows[i][
"LastLoginDate"
].ToString();
UserId = Convert.ToInt32(dt.Rows[i][
""
]);
if
(UserName == username.Value && Password == password.Value)
{
Session[
"NickName"
] = UserName;
Session[
"SchoolCode"
] = SchoolCode;
Session[
"SchoolName"
] = SchoolName;
Session[
"LastLoginDate"
] = LastLogin;
if
(UserId == -1)
{
lblMessage.Text =
"Username and/or password is incorrect."
;
}
else
if
(UserId == -2)
{
lblMessage.Text =
"Account has not been activated."
;
}
else
{
WebMessageBox.Show(
"logged in"
);
}
}
else
{
lblMessage.Text =
"Invalid User Name or Password! Please try again!"
;
}
}
}
}
But this function gives me this error
Column 'Username' does not belong to table .
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: Column 'Username' does not belong to table .
Source Error:
Line 46: for (int
i
=
0
; i
<
RowCount
; i++)
Line 47: {
Line 48:
UserName
=
dt
.Rows[i]["Username"].ToString();
Line 49:
Password
=
dt
.Rows[i]["Password"].ToString();
Line 50:
SchoolCode
=
dt
.Rows[i]["SchoolCode"].ToString();
Below is my stored procedure:
USE [SchoolMIS]
GO
/****** Object: StoredProcedure [dbo].[Validate_User] Script
Date
: 12/11/2017 7:05:30 PM ******/
SET
ANSI_NULLS
ON
GO
SET
QUOTED_IDENTIFIER
ON
GO
ALTER
PROCEDURE
[dbo].[Validate_User]
@Username NVARCHAR(20),
@
Password
NVARCHAR(20)
AS
BEGIN
SET
NOCOUNT
ON
;
DECLARE
@UserId
INT
,
@LastLoginDate DATETIME
SELECT
@UserId = UserId,
@LastLoginDate = LastLoginDate
FROM
Users
WHERE
Username = @Username
AND
[
Password
] = @
Password
IF @UserId
IS
NOT
NULL
BEGIN
IF
NOT
EXISTS(
SELECT
UserId
FROM
UserActivation
WHERE
UserId = @UserId)
BEGIN
UPDATE
Users
SET
LastLoginDate = GETDATE()
WHERE
UserId = @UserId
SELECT
@UserId [UserId]
-- User Valid
END
ELSE
BEGIN
SELECT
-2
-- User not activated.
END
END
ELSE
BEGIN
SELECT
-1
-- User invalid.
END
END
Hope someone can give me an assistance.
Delete Row
Delete Column
Insert Link
×
Insert
Cancel
Embed YouTube Video
×
Width (%)
Height (%)
Insert
Cancel
Table Options
×
Rows
Columns
First row as header
Create Table
Insert Image
×
Selected file:
Alignment
Left
Center
Right
Select an image from your device to upload
Upload to Server
Cancel
Post
Reset
Cancel
Answers (
3
)
Related Discussion