Skip to content
Loading
Spacing Text could not be match in SQL Server 
 Home Controller
 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Data;  
  4. using System.Linq;  
  5. using System.Web;  
  6. using System.Web.Mvc;  
  7.   
  8. namespace dropdownlist.Controllers  
  9. {  
  10.     public class HomeController : Controller  
  11.     {  
  12.         data_access_layer.db dblayer = new data_access_layer.db();  
  13.   
  14.         public ActionResult Index()  
  15.         {  
  16.             city_bind();  
  17.             return View();  
  18.         }  
  19.   
  20.         public void city_bind()  
  21.         {  
  22.             DataSet ds = dblayer.Get_Country();  
  23.   
  24.             List countrylist = new List();  
  25.             foreach (DataRow dr in ds.Tables[0].Rows)  
  26.             {  
  27.                 countrylist.Add(new SelectListItem { Text = dr["city"].ToString(), Value = dr["city"].ToString() });  
  28.   
  29.             }  
  30.             ViewBag.txt_city = countrylist;  
  31.   
  32.         }  
  33.   
  34.         public JsonResult a_add(string city)  
  35.         {  
  36.             DataSet ds = dblayer.Get_A_Add(city);  
  37.             List statelist = new List();  
  38.             foreach (DataRow dr in ds.Tables[0].Rows)  
  39.             {  
  40.                 statelist.Add(new SelectListItem { Text = dr["address2"].ToString(), Value = dr["address2"].ToString() });  
  41.             }  
  42.             return Json(statelist, JsonRequestBehavior.AllowGet);  
  43.   
  44.         }  
  45.   
  46.         public JsonResult b_add(string add)  
  47.         {  
  48.             DataSet ds = dblayer.Get_B_Add(add);  
  49.             List citylist = new List();  
  50.             foreach (DataRow dr in ds.Tables[0].Rows)  
  51.             {  
  52.                 citylist.Add(new SelectListItem { Text = dr["add1"].ToString(), Value = dr["add1"].ToString() });  
  53.             }  
  54.             return Json(citylist, JsonRequestBehavior.AllowGet);  
  55.   
  56.         }  
  57.   
  58.   
  59.         public ActionResult About()  
  60.         {  
  61.             ViewBag.Message = "Your application description page.";  
  62.   
  63.             return View();  
  64.         }  
  65.   
  66.         public ActionResult Contact()  
  67.         {  
  68.             ViewBag.Message = "Your contact page.";  
  69.   
  70.             return View();  
  71.         }  
  72.     }  
  73. }  
 
DB Layer
 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Configuration;  
  4. using System.Data;  
  5. using System.Data.SqlClient;  
  6. using System.Linq;  
  7. using System.Web;  
  8.   
  9. namespace dropdownlist.data_access_layer  
  10. {  
  11.     public class db  
  12.     {  
  13.         SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString);  
  14.           
  15.         //Get Country  
  16.         public DataSet Get_Country()  
  17.         {  
  18.             SqlCommand com = new SqlCommand("select distinct(city) as city from vehicle", con);  
  19.             SqlDataAdapter da = new SqlDataAdapter(com);  
  20.             DataSet ds = new DataSet();  
  21.             da.Fill(ds);  
  22.             return ds;  
  23.   
  24.         }  
  25.         //Get Address  
  26.         public DataSet Get_A_Add(string city)  
  27.         {  
  28.             SqlCommand com = new SqlCommand("select distinct(a_address) as address2 from vehicle where city='"+city+"'", con);  
  29.             SqlDataAdapter da = new SqlDataAdapter(com);  
  30.             DataSet ds = new DataSet();  
  31.             da.Fill(ds);  
  32.             return ds;  
  33.   
  34.         }  
  35.   
  36.         //Get Address  
  37.         public DataSet Get_B_Add(string add)  
  38.         {  
  39.             SqlCommand com = new SqlCommand("select distinct(b_address) as add1 from vehicle where a_address='"+add+"'", con);  
  40.             SqlDataAdapter da = new SqlDataAdapter(com);  
  41.             DataSet ds = new DataSet();  
  42.             da.Fill(ds);  
  43.             return ds;  
  44.   
  45.         }  
  46.     }  
  47. }  
SQl Server Database
 
 
 
 
I am tired Please help.
thanks 

4 Replies

Know the answer? Post it — somebody with the same question will find it here.