Display States according to Country selection... ------we should have two tables in sql------- table: tblcountry create table tblcountry ( countryid varchar(20) primary key, country varchar(20) ) insert into tblcountry values('1','Canada') insert into tblcountry values('2','USA') insert into tblcountry values('3','Nepal') table: tblState create table tblstate ( stateid varchar(20) primary key, state varchar(20), countryid varchar(20) foreign key references tblcountry(countryid) ) insert into tblstate values('1','Alaska','2') insert into tblstate values('2','Puerto Rico','2') insert into tblstate values('3','Saint Thomas','2') --------------run above codes on sql------------- -------------------------------------------------------> <% ConnString="Provider=SQLOLEDB.1;Persist Security Info=False;" ConnString=ConnString & "User ID=sa;Initial Catalog=master;" ConnString=ConnString & "Data Source=computername" 'give your computer name instead of computername 'on "Data Source=computername" on above string Set Conn=server.createobject("ADODB.Connection") Conn.open ConnString Set rs=Server.CreateObject("ADODB.RECORDSET") rs.Open "select * from tblstate",Conn,3 Response.write "" strSQL="select * from tblcountry order by country" rs.Open strSQL,Conn StrCountry=rs("countryid") Set rsstate=server.createobject("ADODB.RECORDSET") rsstate.CursorLocation=adUseClient strSQL="select * from tblstate where countryid='" & StrCountry & "'" rsstate.Open strSQL,Conn %>
Country State/Province <% rsstate.close Set RsState=nothing Conn.close Set Conn=nothing %>