matNYC (3) [Avatar] Offline
#1
Here's my code (the equivalent in VB works fine):

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Text;
using System.Diagnostics;


public partial class DoubleComboXML : System.Web.UI.Page
{
int ct;

protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = "text/xml";

string strQuery=Request.Form["q"];
string strForm=Request.Form["f"];
string strElem=Request.Form["e"];

string strSql = "SELECT " +
" projectName, " +
" departmentID " +
" FROM project " +
" WHERE departmentid =" +
strQuery ;

DataTable dtOptions= FillDataTable(strSql);

StringBuilder strXML=new StringBuilder();
strXML.Append("<?xml " +"version='1.0' ?>");
strXML.Append("<selectChoice>");
strXML.Append("<selectElement>");
strXML.Append("<formName>" + strForm + "</formName>");
strXML.Append("<formElem>" + strElem + "</formElem>");
strXML.Append("</selectElement>");

if (dtOptions.Rows.Count>0)
{
strXML.Append("<entry>");
strXML.Append("<optionText>"+"Select A Territory"+"</optionText>");
strXML.Append("<optionValue>-1" +"</optionValue>");
strXML.Append("</entry>");

foreach(DataRow rw in dtOptions.Rows)
{
strXML.Append("<entry>");
strXML.Append("<optionText>"+rw["projectName"].ToString()+
"</optionText>");
strXML.Append("<optionValue>" +
rw["departmentid"].ToString() +
"</optionValue>");
strXML.Append("</entry>");
}

}

strXML.Append("</selectChoice>");
Response.Write(strXML.ToString());

}

private DataTable FillDataTable(string parStrSQL)
{
SqlConnection strConn =new SqlConnection( "server=myServer;uid=myUID;password=myPasswrd;Database=myDB");
SqlCommand cmd1 =new SqlCommand();
cmd1.Connection=strConn;
cmd1.CommandText=parStrSQL;
cmd1.CommandType=CommandType.Text;

DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd1);
da.Fill(ds);
return ds.Tables[0];
}


}
Pascarello (208) [Avatar] Offline
#2
Re: Double combo: trouble implementing in c#
Did you get this to work?

You probably want to use:

string strQuery = Request.Params.Get("q");
string strForm = Request.Params.Get("f");
string strElem = Request.Params.Get("e");

Eric