Мой запрос такой, и я хочу вставить его, но с помощью SQL Server 2005
insert into postad(cityid,category_id,ad_id,title,ad_description,subcategory_id)
values((select city_id from city where city_name='mumbai'),
(select cat_id from category where cat_name='automobiles & vehicles'),
(select adid from adType where adtype like'wanted'),'myad','itys grwweefa',
(select subcat_id from subcategory where category_id =
(select cat_id from category where cat_name like'automobiles & vehicles')))
Может ли кто-нибудь помочь мне, как мне этого добиться
string city = ddcity.SelectedItem.ToString();
string cat = ddcat.SelectedItem.ToString();
string subcat = ddsubcat.SelectedIndex.ToString();
string adtype = ddadtype.SelectedItem.ToString();
string title = txttitle.Text.Trim();
string description = txtdescription.Text.Trim();
string video = txtvideo.Text.Trim();
DateTime date = DateTime.Now;
SqlConnection myConnection = new SqlConnection("Data Source=DELL-PC\\SQLEXPRESS;Initial Catalog=eclass;Persist Security Info=True;integrated security = true");
string cityq = "select city_id from city where city_name=" + city;
string catq = "select cat_id from category where cat_name=" + cat;
string subq = "select subcat_id from city where subcat_name=" + subcat+"and category_id="+catq;
SqlCommand storead = new SqlCommand("INSERT INTO postad " + "(cityid,category_id,ad_id,title,ad_description,subcategory_id,video,date_creation) " + " values (@city,@cat,@adtype,@title,@description,@subcat,@video,@date)", myConnection);
storead.Parameters.AddWithValue("@title",title);
storead.Parameters.AddWithValue("@city",city);
storead.Parameters.AddWithValue("@cat",cat);
storead.Parameters.AddWithValue("@subcat",subcat);
storead.Parameters.AddWithValue("@adtype",adtype);
storead.Parameters.AddWithValue("@description",description);
storead.Parameters.AddWithValue("@video",video);
storead.Parameters.AddWithValue("@date",date)
Вот как этодолжен работать n идентификаторов являются первичными ключами