Step 1
Create an asp.net MVC Application.
Step 2
Create a table and stored procedure.
Create an asp.net MVC Application.
Step 2
Create a table and stored procedure.
- Create a table.
- Create Table Country(CountryID int Primary key identity(5001,1),CountryName varchar(50))
- Insert data into the table.
- insert Country(CountryName)values('INDIA'),('USA'),('UK'),('IRAN'),('JAPAN')
- Create procedure.
- Create Procedure SP_GetCountry
- as
- begin
- select * from Country
- end
Step 3
Add DataAccessLogic in models folder.
Create a class Country.
Add DataAccessLogic in models folder.
Create a class Country.
- public class Country
- {
- public int CountryID {
- get;
- set;
- }
- public string CountryName {
- get;
- set;
- }
- }
Create a method GetCountry.
- public List < Country > GetCountry() {
- DataSet ds = new DataSet();
- using(SqlConnection con = new SqlConnection(strCon)) {
- using(SqlCommand cmd = new SqlCommand("SP_GetCountry", con)) {
- using(SqlDataAdapter da = new SqlDataAdapter(cmd)) {
- da.Fill(ds);
- }
- }
- }
- List < Country > countries = new List < Country > ();
- for (int i = 0; i < ds.Tables[0].Rows.Count; i++) {
- Country country = new Country();
- country.CountryID = Convert.ToInt32(ds.Tables[0].Rows[i][0]);
- country.CountryName = ds.Tables[0].Rows[i][1].ToString();
- countries;.Add(country);
- country = null;
- }
- return countries;
- }


Join the conversation! Your thoughts help the community grow.