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
Sourav Kumar Das
527
2.5k
171.5k
Get Maximum Value of maxid from database in MVC
Jan 22 2019 4:01 AM
How to get maximum value of 'max id' from database in Asp.Net MVC?
Sample Reference Code:
In Controller:
public
ActionResult getClientId()
{
ClientMaster objCliMas =
new
ClientMaster();
DataSet ds =
new
DataSet();
string
sQuery =
" SELECT ISNULL(MAX(ClientId), 0)+1 'MaxClientId' FROM PMS_ClientMaster "
;
SqlDataAdapter da =
new
SqlDataAdapter(sQuery, con);
con.Open();
da.Fill(ds);
con.Close();
if
(ds.Tables[0].Rows.Count > 0)
{
objCliMas.Id = Convert.ToInt32(ds.Tables[0].Rows[0][
"MaxClientId"
].ToString());
}
return
View(objCliMas);
}
In View:
@Html.EditorFor(model => model.Id,
new
{ htmlAttributes =
new
{ @
class
=
"form-control"
} })
@Html.ValidationMessageFor(model => model.Id,
""
,
new
{ @
class
=
"text-danger"
})
At here in the view it's not displaying the maxid value.
If there's any solution please let me know it.
Reply
Answers (
4
)
Get the dropdown list of selected value and text in MVC
Getting error on using partial view in asp.net core 2.2