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
Guest User
Tech Writer
2.1k
486.5k
Save data in DB in asp.net mvc without entity framework?
Mar 20 2020 3:05 AM
Hi Team
I want to find an example as to how to save record from a form to database table. Im not using entity framework, i have connectionString on web.config. Please share any useful relevant example to my requirement mates.
Reply
Answers (
3
)
0
Ravi Patel
271
6.8k
1.4m
Mar 20 2020 4:02 AM
Hi,
refer this
https://www.c-sharpcorner.com/UploadFile/0c1bb2/insertupdatedelete-in-Asp-Net-mvc-5-using-ado-net/
https://www.c-sharpcorner.com/UploadFile/francissvk/crud-operations-in-Asp-Net-mvc-using-ado-net/
0
Guest User
Tech Writer
2.1k
486.5k
Mar 20 2020 3:19 AM
Here what i want to do exactly, i am using connection string to attempt this and have this logic below. Somehow i am beginning to get stuck in the middle.
private
SqlConnection con;
// private method for connection.
private
void
connection()
{
string
constr = ConfigurationManager.ConnectionStrings[
"DefConnection"
].ToString();
con =
new
SqlConnection(constr);
}
//GET:/Manage/AddNewDetails.
public
ActionResult AddNewDetails()
{
return
View();
}
//POST://Manage to add-new-details.
[HttpPost]
public
ActionResult AdAddNewDetails(EditTrainingRegFormViewModel model)
{
// logic here.
return
View();
}
// Model class
public
class
EditTrainingRegFormViewModel
{
public
string
Title {
get
;
set
; }
public
string
FirstName {
get
;
set
; }
public
string
LastName {
get
;
set
; }
public
string
Position {
get
;
set
; }
public
string
Company {
get
;
set
; }
public
string
Address {
get
;
set
; }
[Display(Name =
"Choose country"
)]
public
int
? SelectedCountryId {
get
;
set
; }
[Required]
[RegularExpression(@
"^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$"
)]
[Display(Name=
"Postal/Zip Code"
)]
public
string
Code {
get
;
set
; }
[DataType(DataType.Text)]
[Required(ErrorMessage =
"This field is required"
)]
public
string
City {
get
;
set
; }
public
string
State {
get
;
set
; }
[Required(ErrorMessage =
"This field is required"
)]
public
string
Cell_Number {
get
;
set
; }
public
List<CheckBox> Dietary_requirement =
new
List<CheckBox>();
[Required(ErrorMessage =
"This field is required"
)]
[EmailAddress(ErrorMessage =
"Enter correct email"
)]
[RegularExpression(@
"^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$"
)]
public
string
Email {
get
;
set
; }
public
int
Country_Id {
get
;
set
; }
public
string
Country_Name {
get
;
set
; }
}
0
Mario Scheeren
550
2.1k
35.9k
Mar 20 2020 3:12 AM
Take a look at this here: https://dapper-tutorial.net/dapper
How to create checkbox on asp.net mvc?
Mouse Hover the image control and display it detailto labels