Click here to Skip to main content
15,881,455 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Hy Dear
Am already work on asp.net with ado.net .now i want to use ado.net with asp.net MVC
but dont know how to pass value html controls to controller on button click even
and what is entity framework am stuck in what is code first, model first or db first in entity framework

What I have tried:

How to insert data with ado.net in mvc with html controls
Posted
Updated 25-Apr-17 0:13am
v2
Comments
F-ES Sitecore 20-Jan-17 4:39am    
Passing data from view to controllers etc is basic MVC 101. We can't teach you a new technology from scratch over a "Quick Answer" forum post. Get a book on MVC and go through it to learn the basics, or at least go through some on-line tutorials, eg google "mvc book store"
Hemant Singh Rautela 20-Jan-17 5:36am    
"What I have tried: "
Did you try something ? I don't think so. You have to read from start & you can see online video-tutorial. there are many available for basic, & you can search CRUD operation in MVC...

http://tutlane.com/tutorial/aspnet-mvc/ado-net-crud-operations-insert-update-delete-in-asp-net-mvc-4-example

1 solution

Hi,
For Insert Record From View to Controller use this code to your Controller

private SqlConnection con;
//To Handle connection related activities
private void connection()
{
string constr = ConfigurationManager.ConnectionStrings["getconn"].ToString();
con = new SqlConnection(constr);

}
//To Add Employee details
public bool AddEmployee(EmpModel obj)
{

connection();
SqlCommand com = new SqlCommand("AddNewEmpDetails", con);
com.CommandType = CommandType.StoredProcedure;
com.Parameters.AddWithValue("@Name", obj.Name);
com.Parameters.AddWithValue("@City", obj.City);
com.Parameters.AddWithValue("@Address", obj.Address);

con.Open();
int i = com.ExecuteNonQuery();
con.Close();
if (i >= 1)
{

return true;

}
else
{

return false;
}


}

and SP Code is From SQL Side
Create procedure [dbo].[AddNewEmpDetails]
(
@Name varchar (50),
@City varchar (50),
@Address varchar (50)
)
as
begin
Insert into Employee values(@Name,@City,@Address)
End
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900