Running Query From Dropdown Box

Running SQL Query From Dropdown Box

Page 1 of 1

13 Replies - 1733 Views - Last Post: 28 October 2008 - 01:30 PM Rate Topic: -----

#1 AFProgMan  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 80
  • Joined: 21-October 08

Running Query From Dropdown Box

Posted 27 October 2008 - 07:16 AM

Hey everyone,

I am looking for the best way to post back info into some text boxes designed for editing a record in the SQL table. I have it/want it set up so when a record is chosen from the dropdown box it populates all of the information into the desired text fields. This way i can edit the information available and then update that record.

What is a generic line of code that would get this to happen?

I will post my code when I at least make the effort to gather the query info.

-Kev

Is This A Good Question/Topic? 0
  • +

Replies To: Running Query From Dropdown Box

#2 AFProgMan  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 80
  • Joined: 21-October 08

Re: Running Query From Dropdown Box

Posted 27 October 2008 - 07:29 AM

Here is my code for retrieving the directory listing and deleting the the directory listing when required. DO I need to create a whole separate edit function/query? Or can i utilize the GetDirectoryListings function to display the information into my edit view?

using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Logger;

/// <summary>
/// Summary description for directorylistings
/// </summary>
public class directorylistings : data
{
	private static string oConn = ConfigurationManager.AppSettings["connstring"];

	public static DataSet GetDirectoryListings()
	{
		return _getDirectoryListings();
	}
	private static DataSet _getDirectoryListings()
	{
		string oString = "Select reftype, refid ,reffirstname, reflastname, reffirmname, refspecialty, refaddress, refcity, refstate, refzipcode, refphoneareacode, refphonenumber, reffaxareacode, reffaxnumber, refemailaddress, refwebsiteaddress, refdescription "
			+ "From tbl_ReferralDirectory "
			+ "Order by refstate, refspecialty";

		string DataTable_Name = "tbl_ReferralDirectory";

		DataSet DS = new DataSet();
		SqlDataAdapter oAdapter = new SqlDataAdapter(oString, oConn);
		oAdapter.Fill(DS, DataTable_Name);

		return DS;
	}

	public static DataSet GetReferralByID(int refid)
	{
		return _getReferralByID(refid);
	}
	private static DataSet _getReferralByID(int refid)
	{
		string oConn = ConfigurationManager.AppSettings["connstring"];
		string oString = "Select refid, reftype, reffirstname, reflastname, reffirmname, refspecialty, refaddress, refcity, refstate, refzipcode, refphoneareacode, refphonenumber, reffaxareacode, reffaxnumber, refemailaddress, refwebsiteaddress, refdescription "
			+ "From tbl_ReferralDirectory "
			+ "Where refid = " + refid;

		string DataTable_Name = "tbl_ReferralDirectory";

		DataSet DS = new DataSet();
		SqlDataAdapter oAdapter = new SqlDataAdapter(oString, oConn);
		oAdapter.Fill(DS, DataTable_Name);
		return DS;
	}

	public static DataSet GetLatestDirectoryListings()
	{
		return _getLatestDirectoryListings();
	}
	private static DataSet _getLatestDirectoryListings()
	{
		string oString = "Select refid, reftype, reffirstname, reflastname, reffirmname, refspecialty, refaddress, refcity, refstate, refzipcode, refphoneareacode, refphonenumber, reffaxareacode, reffaxnumber, refemailaddress, refwebsiteaddress, refdescription "
			+ "From tbl_ReferralDirectory "
			+ "Order by refid desc";

		string DataTable_Name = "tbl_ReferralDirectory";

		DataSet DS = new DataSet();
		SqlDataAdapter oAdapter = new SqlDataAdapter(oString, oConn);
		oAdapter.Fill(DS, DataTable_Name);

		return DS;
	}

	public static bool Insert(string strtype, string strfirstname, string strlastname, string strfirmname, string strspecialty,
		string straddress, string strcity, string strstate, string strpostalcode, string strphoneareacode, string strphonenumber,
		string strfaxareacode, string strfaxnumber, string stremail, string strwebsite, string strdescription)
	{
		return _insert(strtype, strfirstname, strlastname, strfirmname, strspecialty, straddress, strcity,
				strstate, strpostalcode, strphoneareacode, strphonenumber, strfaxareacode, strfaxnumber, stremail, strwebsite, strdescription);
	}
	private static bool _insert(string strtype, string strfirstname, string strlastname, string strfirmname, string strspecialty,
		string straddress, string strcity, string strstate, string strpostalcode, string strphoneareacode, string strphonenumber,
		string strfaxareacode, string strfaxnumber, string stremail, string strwebsite, string strdescription)
	{

		SqlConnection oConn;
		oConn = new SqlConnection(ConfigurationManager.AppSettings["connstring"]);
		string oString = "Insert Into tbl_ReferralDirectory(reftype, reffirstname, reflastname, reffirmname, refspecialty, refaddress, refcity, refstate, refzipcode, refphoneareacode, refphonenumber, reffaxareacode, reffaxnumber, refemailaddress, refwebsiteaddress, refdescription) values(@type, @firstname, @lastname, @firm, @specialty, @address, @city, @state, @postalcode, @phoneareacode, @phonenumber, @faxareacode, @faxnumber, @email, @website, @description) ";

		SqlCommand ocommand = new SqlCommand(oString, oConn);
		ocommand.Parameters.Add(new SqlParameter("@type", strtype));
		ocommand.Parameters.Add(new SqlParameter("@firstname", strfirstname));
		ocommand.Parameters.Add(new SqlParameter("@lastname", strlastname));
		ocommand.Parameters.Add(new SqlParameter("@firm", strfirmname));
		ocommand.Parameters.Add(new SqlParameter("@specialty", strspecialty));
		ocommand.Parameters.Add(new SqlParameter("@address", straddress));
		ocommand.Parameters.Add(new SqlParameter("@city", strcity));
		ocommand.Parameters.Add(new SqlParameter("@state", strstate));
		ocommand.Parameters.Add(new SqlParameter("@postalcode", strpostalcode));
		ocommand.Parameters.Add(new SqlParameter("@phoneareacode", strphoneareacode));
		ocommand.Parameters.Add(new SqlParameter("@phonenumber", strphonenumber));
		ocommand.Parameters.Add(new SqlParameter("@faxareacode", strfaxareacode));
		ocommand.Parameters.Add(new SqlParameter("@faxnumber", strfaxnumber));
		ocommand.Parameters.Add(new SqlParameter("@email", stremail));
		ocommand.Parameters.Add(new SqlParameter("@website", strwebsite));
		ocommand.Parameters.Add(new SqlParameter("@description", strdescription));

		try
		{
			oConn.Open();
			ocommand.ExecuteNonQuery();
		}
		catch (Exception ee)
		{
			bool bReturnLog = false;
			ErrorLog.LogFilePath = "ErrorLogFile.txt";
			bReturnLog = ErrorLog.ErrorRoutine(false, ee);
			return false;
		}

		oConn.Close();
		oConn.Dispose();

		return true;
	}

	public static bool DeleteReferralByID(int intrefid)
	{
		return _deleteReferralByID(intrefid);
	}
	private static bool _deleteReferralByID(int intrefid)
	{

		SqlConnection oConn;
		oConn = new SqlConnection(ConfigurationManager.AppSettings["connstring"]);

		string oString = "Delete From tbl_ReferralDirectory Where refid = @refid";

		SqlCommand ocommand = new SqlCommand(oString, oConn);
		ocommand.Parameters.Add(new SqlParameter("@refid", intrefid));

		try
		{
			oConn.Open();
			ocommand.ExecuteNonQuery();
		}
		catch (Exception ee)
		{
			bool bReturnLog = false;
			ErrorLog.LogFilePath = "ErrorLogFile.txt";
			bReturnLog = ErrorLog.ErrorRoutine(false, ee);
			return false;
		}

		oConn.Close();
		oConn.Dispose();

		return true;
	}
}



This is what I have set up for my 3rd view(my edit view)

<asp:View ID="View3" runat="server">
<div width="auto" style="height: 45px">
	<table id="EditRefer" border="0">
	
		<asp:DropDownList ID="cboChooseRef" runat="server" 
			DataSourceID="SqlDataSource1" 
			onselectedindexchanged="DropDownList1_SelectedIndexChanged" 
			AutoPostBack="True">
		</asp:DropDownList>
		<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
			ConnectionString="<%$ ConnectionStrings:PLNIndexConnectionString %>" 
			SelectCommand="SELECT [reffirstname], [reflastname] FROM [tbl_ReferralDirectory]">
		</asp:SqlDataSource>
	
	</table>
	<br />
	<asp:Label ID="Label1" runat="server" Text="Now Editing Referral:"></asp:Label><asp:Label ID="EditRefID" runat="server" Text=""></asp:Label><br />
	<asp:TextBox ID="EditRefFirst" runat="server" Width="236px"></asp:TextBox><br />
	<asp:TextBox ID="EditRefLast" runat="server" Width="236px"></asp:TextBox><br />
	<asp:TextBox ID="EditRefFirm" runat="server" Width="236px"></asp:TextBox><br />
	<asp:TextBox ID="EditRefSpec" runat="server" Width="236px"></asp:TextBox><br />
	<asp:TextBox ID="EditRefAddress" runat="server" Width="236px"></asp:TextBox><br />
	<asp:TextBox ID="EditRefCity" runat="server" Width="236px"></asp:TextBox><br />
	<asp:TextBox ID="EditRefZipcode" runat="server" Width="236px"></asp:TextBox><br />
	<asp:TextBox ID="EditRefPhnArea" runat="server" Width="236px"></asp:TextBox><br />
	<asp:TextBox ID="EditRefPhnNum" runat="server" Width="236px"></asp:TextBox><br />
	<asp:TextBox ID="EditRefFaxArea" runat="server" Width="236px"></asp:TextBox><br />
	<asp:TextBox ID="EditRefFaxNum" runat="server" Width="236px"></asp:TextBox><br />
	<asp:TextBox ID="EditRefEmail" runat="server" Width="236px"></asp:TextBox><br />
	<asp:TextBox ID="EditRefWebsite" runat="server" Width="236px"></asp:TextBox><br />
	<asp:TextBox ID="EditRefDesc" runat="server" Width="236px"></asp:TextBox>
	
	<br />
	<br />
	<asp:Button ID="CmdRefEdit" runat="server" Text="Submit Changes" 
		Width="135px" />
	
	<br />


</div>
	
</asp:View>


Any ideas?
Was This Post Helpful? 0
  • +
  • -

#3 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Running Query From Dropdown Box

Posted 27 October 2008 - 07:32 AM

There isn't a generic line of code that will do as you ask. The Sql will need to be tailored to your specific database and tables.

Do you know how to put together a Sql Select statement?

Sql Where Clause
Was This Post Helpful? 0
  • +
  • -

#4 AFProgMan  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 80
  • Joined: 21-October 08

Re: Running Query From Dropdown Box

Posted 27 October 2008 - 07:56 AM

SELECT *
FROM tbl_ReferralDirectory
WHERE refID = EditRefID

I know my SQL statements. And the queries can be altered later.

I am more interested in how to relay that info into my fields.
Was This Post Helpful? 0
  • +
  • -

#5 AFProgMan  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 80
  • Joined: 21-October 08

Re: Running Query From Dropdown Box

Posted 27 October 2008 - 08:44 AM

This is what i have so far.

DirectoryListings.CS
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Logger;

/// <summary>
/// Summary description for directorylistings
/// </summary>
public class directorylistings : data
{
	private static string oConn = ConfigurationManager.AppSettings["connstring"];

	public static DataSet GetDirectoryListings()
	{
		return _getDirectoryListings();
	}
	private static DataSet _getDirectoryListings()
	{
		string oString = "Select reftype, refid ,reffirstname, reflastname, reffirmname, refspecialty, refaddress, refcity, refstate, refzipcode, refphoneareacode, refphonenumber, reffaxareacode, reffaxnumber, refemailaddress, refwebsiteaddress, refdescription "
			+ "From tbl_ReferralDirectory "
			+ "Order by refstate, refspecialty";

		string DataTable_Name = "tbl_ReferralDirectory";

		DataSet DS = new DataSet();
		SqlDataAdapter oAdapter = new SqlDataAdapter(oString, oConn);
		oAdapter.Fill(DS, DataTable_Name);

		return DS;
	}

	public static DataSet GetReferralByID(int refid)
	{
		return _getReferralByID(refid);
	}
	private static DataSet _getReferralByID(int refid)
	{
		string oConn = ConfigurationManager.AppSettings["connstring"];
		string oString = "Select refid, reftype, reffirstname, reflastname, reffirmname, refspecialty, refaddress, refcity, refstate, refzipcode, refphoneareacode, refphonenumber, reffaxareacode, reffaxnumber, refemailaddress, refwebsiteaddress, refdescription "
			+ "From tbl_ReferralDirectory "
			+ "Where refid = " + refid;

		string DataTable_Name = "tbl_ReferralDirectory";

		DataSet DS = new DataSet();
		SqlDataAdapter oAdapter = new SqlDataAdapter(oString, oConn);
		oAdapter.Fill(DS, DataTable_Name);
		return DS;
	}

	public static DataSet GetLatestDirectoryListings()
	{
		return _getLatestDirectoryListings();
	}
	private static DataSet _getLatestDirectoryListings()
	{
		string oString = "Select refid, reftype, reffirstname, reflastname, reffirmname, refspecialty, refaddress, refcity, refstate, refzipcode, refphoneareacode, refphonenumber, reffaxareacode, reffaxnumber, refemailaddress, refwebsiteaddress, refdescription "
			+ "From tbl_ReferralDirectory "
			+ "Order by refid desc";

		string DataTable_Name = "tbl_ReferralDirectory";

		DataSet DS = new DataSet();
		SqlDataAdapter oAdapter = new SqlDataAdapter(oString, oConn);
		oAdapter.Fill(DS, DataTable_Name);

		return DS;
	}

	public static bool Insert(string strtype, string strfirstname, string strlastname, string strfirmname, string strspecialty,
		string straddress, string strcity, string strstate, string strpostalcode, string strphoneareacode, string strphonenumber,
		string strfaxareacode, string strfaxnumber, string stremail, string strwebsite, string strdescription)
	{
		return _insert(strtype, strfirstname, strlastname, strfirmname, strspecialty, straddress, strcity,
				strstate, strpostalcode, strphoneareacode, strphonenumber, strfaxareacode, strfaxnumber, stremail, strwebsite, strdescription);
	}
	private static bool _insert(string strtype, string strfirstname, string strlastname, string strfirmname, string strspecialty,
		string straddress, string strcity, string strstate, string strpostalcode, string strphoneareacode, string strphonenumber,
		string strfaxareacode, string strfaxnumber, string stremail, string strwebsite, string strdescription)
	{

		SqlConnection oConn;
		oConn = new SqlConnection(ConfigurationManager.AppSettings["connstring"]);
		string oString = "Insert Into tbl_ReferralDirectory(reftype, reffirstname, reflastname, reffirmname, refspecialty, refaddress, refcity, refstate, refzipcode, refphoneareacode, refphonenumber, reffaxareacode, reffaxnumber, refemailaddress, refwebsiteaddress, refdescription) values(@type, @firstname, @lastname, @firm, @specialty, @address, @city, @state, @postalcode, @phoneareacode, @phonenumber, @faxareacode, @faxnumber, @email, @website, @description) ";

		SqlCommand ocommand = new SqlCommand(oString, oConn);
		ocommand.Parameters.Add(new SqlParameter("@type", strtype));
		ocommand.Parameters.Add(new SqlParameter("@firstname", strfirstname));
		ocommand.Parameters.Add(new SqlParameter("@lastname", strlastname));
		ocommand.Parameters.Add(new SqlParameter("@firm", strfirmname));
		ocommand.Parameters.Add(new SqlParameter("@specialty", strspecialty));
		ocommand.Parameters.Add(new SqlParameter("@address", straddress));
		ocommand.Parameters.Add(new SqlParameter("@city", strcity));
		ocommand.Parameters.Add(new SqlParameter("@state", strstate));
		ocommand.Parameters.Add(new SqlParameter("@postalcode", strpostalcode));
		ocommand.Parameters.Add(new SqlParameter("@phoneareacode", strphoneareacode));
		ocommand.Parameters.Add(new SqlParameter("@phonenumber", strphonenumber));
		ocommand.Parameters.Add(new SqlParameter("@faxareacode", strfaxareacode));
		ocommand.Parameters.Add(new SqlParameter("@faxnumber", strfaxnumber));
		ocommand.Parameters.Add(new SqlParameter("@email", stremail));
		ocommand.Parameters.Add(new SqlParameter("@website", strwebsite));
		ocommand.Parameters.Add(new SqlParameter("@description", strdescription));

		try
		{
			oConn.Open();
			ocommand.ExecuteNonQuery();
		}
		catch (Exception ee)
		{
			bool bReturnLog = false;
			ErrorLog.LogFilePath = "ErrorLogFile.txt";
			bReturnLog = ErrorLog.ErrorRoutine(false, ee);
			return false;
		}

		oConn.Close();
		oConn.Dispose();

		return true;
	}

	public static bool DeleteReferralByID(int intrefid)
	{
		return _deleteReferralByID(intrefid);
	}
	private static bool _deleteReferralByID(int intrefid)
	{

		SqlConnection oConn;
		oConn = new SqlConnection(ConfigurationManager.AppSettings["connstring"]);

		string oString = "Delete From tbl_ReferralDirectory Where refid = @refid";

		SqlCommand ocommand = new SqlCommand(oString, oConn);
		ocommand.Parameters.Add(new SqlParameter("@refid", intrefid));

		try
		{
			oConn.Open();
			ocommand.ExecuteNonQuery();
		}
		catch (Exception ee)
		{
			bool bReturnLog = false;
			ErrorLog.LogFilePath = "ErrorLogFile.txt";
			bReturnLog = ErrorLog.ErrorRoutine(false, ee);
			return false;
		}

		oConn.Close();
		oConn.Dispose();

		return true;
	}
	public static bool GetRefInfo(int EditRefID)
	{
		return _getrefinfo(EditRefID);
	}
	private static bool _getrefinfo(int EditRefId)
	{
		SqlConnection oConn;
		oConn = new SqlConnection(ConfigurationManager.AppSettings["connstring"]);

		string oString = "Select * From tbl_ReferralDirectory Where refid = @erefid";

		SqlCommand ocommand = new SqlCommand(oString, oConn);
		ocommand.Parameters.Add(new SqlParameter("@erefid", refid));
		DataSet DS = new DataSet();
		SqlDataAdapter oAdapter = new SqlDataAdapter(oString, oConn);
		oAdapter.Fill(DS, DataTable_Name);

		return DS;
	}

	public static bool Insert(string erefid, string estrtype, string estrfirstname, string estrlastname, string estrfirmname, string estrspecialty,
		string estraddress, string estrcity, string estrstate, string estrpostalcode, string estrphoneareacode, string estrphonenumber,
		string estrfaxareacode, string estrfaxnumber, string estremail, string estrwebsite, string estrdescription)
	{
		return _insert(erefid, estrtype, estrfirstname, estrlastname, estrfirmname, estrspecialty, estraddress, estrcity,
				estrstate, estrpostalcode, estrphoneareacode, estrphonenumber, estrfaxareacode, estrfaxnumber, estremail, estrwebsite, estrdescription);
	}
	private static bool _insert(string erefid, string estrtype, string estrfirstname, string estrlastname, string estrfirmname, string estrspecialty,
		string estraddress, string estrcity, string estrstate, string estrpostalcode, string estrphoneareacode, string estrphonenumber,
		string estrfaxareacode, string estrfaxnumber, string estremail, string estrwebsite, string estrdescription)
	{

		SqlConnection oConn;
		oConn = new SqlConnection(ConfigurationManager.AppSettings["connstring"]);
		string oString = "Insert Into tbl_ReferralDirectory(refid, reffirstname, reflastname, reffirmname, refspecialty, refaddress, refcity, refstate, refzipcode, refphoneareacode, refphonenumber, reffaxareacode, reffaxnumber, refemailaddress, refwebsiteaddress, refdescription) values(@refid, @efirstname, @elastname, @efirm, @especialty, @eaddress, @ecity, @estate, @epostalcode, @ephoneareacode, @ephonenumber, @efaxareacode, @efaxnumber, @eemail, @ewebsite, @edescription) ";


		SqlCommand ocommand = new SqlCommand(oString, oConn);
		//ocommand.Parameters.Add(new SqlParameter("@etype", estrtype));
		ocommand.Parameters.Add(new SqlParameter("@erefid", erefid));
		ocommand.Parameters.Add(new SqlParameter("@efirstname", estrfirstname));
		ocommand.Parameters.Add(new SqlParameter("@elastname", estrlastname));
		ocommand.Parameters.Add(new SqlParameter("@efirm", estrfirmname));
		ocommand.Parameters.Add(new SqlParameter("@especialty", estrspecialty));
		ocommand.Parameters.Add(new SqlParameter("@eaddress", estraddress));
		ocommand.Parameters.Add(new SqlParameter("@ecity", estrcity));
		ocommand.Parameters.Add(new SqlParameter("@estate", estrstate));
		ocommand.Parameters.Add(new SqlParameter("@epostalcode", estrpostalcode));
		ocommand.Parameters.Add(new SqlParameter("@ephoneareacode", estrphoneareacode));
		ocommand.Parameters.Add(new SqlParameter("@ephonenumber", estrphonenumber));
		ocommand.Parameters.Add(new SqlParameter("@efaxareacode", estrfaxareacode));
		ocommand.Parameters.Add(new SqlParameter("@efaxnumber", estrfaxnumber));
		ocommand.Parameters.Add(new SqlParameter("@eemail", estremail));
		ocommand.Parameters.Add(new SqlParameter("@ewebsite", estrwebsite));
		ocommand.Parameters.Add(new SqlParameter("@edescription", estrdescription));

		try
		{
			oConn.Open();
			ocommand.ExecuteNonQuery();
		}
		catch (Exception ee)
		{
			bool bReturnLog = false;
			ErrorLog.LogFilePath = "ErrorLogFile.txt";
			bReturnLog = ErrorLog.ErrorRoutine(false, ee);
			return false;
		}

		oConn.Close();
		oConn.Dispose();

		return true;
	}
}




Includes/Private/adminReferralDirectory.ASCX
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="adminReferralDirectory.ascx.cs" Inherits="includes__private_adminReferralDirectory" %>
<style type="text/css">
	.style1
	{
		width: 1px;
		height: 122px;
	}
	.style2
	{
		width: 136px;
		height: 122px;
	}
	.style3
	{
		height: 122px;
	}
	.tab
	{
	}
	.tabs
	{
	}
	.text
	{
	}
	.notices
	{
	}
	.selectedTab
	{
	}
	.tabContents
	{
	}
</style>
<div>
<asp:Menu ID="Menu1" Orientation="Horizontal" StaticMenuItemStyle-CssClass="tab"
	StaticSelectedStyle-CssClass="selectedTab" CssClass="tabs" OnMenuItemClick="Menu1_MenuItemClick"
	runat="server">
	<Items>
		<asp:MenuItem Text="Add Referral" Value="0" Selected="true" />
		<asp:MenuItem Text="Delete Referrals" Value="1" />
		<asp:MenuItem Text="Edit Referrals" Value="2" />	  
	</Items>
</asp:Menu>
<div class="tabContents">
<asp:MultiView ID="MultiView1" ActiveViewIndex="0" runat="server">
<asp:View ID="View1" runat="server">
<table border="0" cellpadding="0" cellspacing="2" width="600">
 <tr>
	<td style="width: 1px">
		<span style="color: #ff0000">*</span></td>
	<td style="width: 136px">
		<asp:Label ID="lblRefType" runat="server" CssClass="text" Text="Referral Type"></asp:Label></td>
	<td>
		<asp:DropDownList ID="cboRTypes" runat="server" Width="279px" DataTextField="GRefType"
			DataValueField="TypeVal" >
			<asp:ListItem>Lawyer</asp:ListItem>
			<asp:ListItem>ExpertWitness</asp:ListItem>
		</asp:DropDownList>
		&nbsp;
		<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ControlToValidate="cboRTypes"
			Display="Dynamic" ErrorMessage="Required Field!" SetFocusonerror="True" ValidationGroup="Referrals"></asp:RequiredFieldValidator></td>
</tr>
 <tr>
	<td style="width: 1px">
		<span style="color: #ff0000">*</span></td>
	<td style="width: 136px">
		<asp:Label ID="lblRefFirstName" runat="server" CssClass="text" Text="Referral First Name"></asp:Label></td>
	<td>
		<asp:TextBox ID="txtRefFirstName" runat="server" Width="279px"></asp:TextBox>&nbsp;
		<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtRefFirstName"
			Display="Dynamic" ErrorMessage="Required Field!" SetFocusonerror="True" ValidationGroup="Referrals"></asp:RequiredFieldValidator></td>
</tr>
<tr>
	<td style="width: 1px">
		<span style="color: #ff0000">*</span></td>
	<td style="width: 136px">
		<asp:Label ID="lblRefLastName" runat="server" CssClass="text" Text="Referral Last Name"></asp:Label></td>
	<td>
		<asp:TextBox ID="txtRefLastName" runat="server" Width="279px"></asp:TextBox>&nbsp;
		<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtRefLastName"
			Display="Dynamic" ErrorMessage="Required Field!" SetFocusonerror="True" ValidationGroup="Referrals"></asp:RequiredFieldValidator></td>
</tr>
<tr>
	<td style="width: 1px; height: 24px;">
		<span style="color: #ff0000">*</span></td>
	<td style="width: 136px; height: 24px;">
		<asp:Label ID="lblRefFirmName" runat="server" CssClass="text" Text="Referral Firm Name"></asp:Label></td>
	<td style="height: 24px">
		<asp:TextBox ID="txtRefFirmName" runat="server" Width="279px"></asp:TextBox>&nbsp;
		<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtRefFirmName"
			Display="Dynamic" ErrorMessage="Required Field!" SetFocusonerror="True" ValidationGroup="Referrals"></asp:RequiredFieldValidator></td>
</tr>
<tr>
	<td style="width: 1px">
		<span style="color: #ff0000">*</span></td>
	<td style="width: 136px">
		<asp:Label ID="lblRefSpecialty" runat="server" CssClass="text" Text="Referral Specialty"></asp:Label></td>
	<td>
		<asp:TextBox ID="txtRefSpecialty" runat="server" Width="279px"></asp:TextBox>&nbsp;
		<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="txtRefSpecialty"
			Display="Dynamic" ErrorMessage="Required Field!" SetFocusonerror="True" ValidationGroup="Referrals"></asp:RequiredFieldValidator></td>
</tr>
<tr>
	<td style="width: 1px">
	 <span style="color: #ff0000">*</span></td>
	<td style="width: 136px">
		<asp:Label ID="lblRefAddress" runat="server" CssClass="text" Text="Referral Address"></asp:Label></td>
	<td>
		<asp:TextBox ID="txtRefAddress" runat="server" Width="279px"></asp:TextBox>&nbsp;
		 <asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server" ControlToValidate="txtRefAddress"
			Display="Dynamic" ErrorMessage="Required Field!" SetFocusonerror="True" ValidationGroup="Referrals"></asp:RequiredFieldValidator>
	</td>
</tr>
<tr>
	<td style="width: 1px">
		<span style="color: #ff0000">*</span></td>
	<td style="width: 136px">
	<asp:Label ID="lblRefCity" runat="server" CssClass="text" Text="Referral City"></asp:Label></td>
	<td>
		<asp:TextBox ID="txtRefCity" runat="server" Width="279px"></asp:TextBox>&nbsp;
		<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="txtRefCity"
			Display="Dynamic" ErrorMessage="Required Field!" SetFocusonerror="True" ValidationGroup="Referrals"></asp:RequiredFieldValidator></td>
</tr>
<tr>
	<td style="width: 1px">
		<span style="color: #ff0000">*</span></td>
	<td style="width: 136px">
		<asp:Label ID="lblRefState" runat="server" CssClass="text" Text="Referral State"></asp:Label></td>
	<td>
		<asp:DropDownList ID="cboStates" runat="server" Width="277px" DataTextField="State"
			DataValueField="Abbrev" />&nbsp;
		<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ControlToValidate="cboStates"
			Display="Dynamic" ErrorMessage="Required Field!" SetFocusonerror="True" ValidationGroup="Referrals"></asp:RequiredFieldValidator></td>
</tr>
<tr>
	<td style="width: 1px">
	<span style="color: #ff0000">*</span>
	</td>
	<td style="width: 136px">
		<asp:Label ID="lblRefPostalCode" runat="server" CssClass="text" Text="Referral Postal Code"></asp:Label></td>
	<td>
	<asp:TextBox ID="txtRefPostalCode" runat="server" Width="279px"></asp:TextBox>&nbsp;
	<asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server" ControlToValidate="txtRefPostalCode"
		Display="Dynamic" ErrorMessage="Required Field!" SetFocusonerror="True" ValidationGroup="Referrals"></asp:RequiredFieldValidator>
	</td>
</tr>
<tr>
	<td style="width: 1px; height: 24px">
		</td>
	<td style="height: 24px; width: 136px;">
		<asp:Label ID="lblRefPhoneNumber" runat="server" CssClass="text" Text="Referral Phone #"></asp:Label></td>
	<td style="height: 24px">
		<asp:TextBox ID="txtRefPhoneNumberAreaCode" runat="server" Width="51px"></asp:TextBox>&nbsp;
		<asp:TextBox ID="txtRefPhoneNumber" runat="server" Width="219px"></asp:TextBox>&nbsp;
	   </td>
</tr>
<tr>
	<td style="width: 1px; height: 24px">
	   </td>
	<td style="height: 24px; width: 136px;">
		<asp:Label ID="lblRefFaxNumber" runat="server" CssClass="text" Text="Referral Fax #"></asp:Label></td>
	<td style="height: 24px">
		<asp:TextBox ID="txtRefFaxNumberAreaCode" runat="server" Width="51px"></asp:TextBox>&nbsp;
		<asp:TextBox ID="txtRefFaxNumber" runat="server" Width="219px"></asp:TextBox>&nbsp;
		</td>
</tr>
<tr>
	<td style="width: 1px">
	</td>
	<td style="width: 136px">
		<asp:Label ID="lblRefEmailAddress" runat="server" CssClass="text" Text="Referral Email Address"></asp:Label></td>
	<td>
	<asp:TextBox ID="txtRefEmailAddress" runat="server" Width="279px"></asp:TextBox>
	</td>
</tr>
<tr>
	<td style="width: 1px">
	</td>
	<td style="width: 136px">
		<asp:Label ID="lblRefWebsite" runat="server" CssClass="text" Text="Referral Website"></asp:Label></td>
	<td>
	<asp:TextBox ID="txtRefWebsite" runat="server" Width="279px"></asp:TextBox>
	</td>
</tr>
 <tr>
	<td class="style1">
	</td>
	<td class="style2">
	<asp:Label ID="Label2" runat="server" CssClass="text" Text="Referral Description"></asp:Label>
		&nbsp;</td>
	<td class="style3">
	<asp:TextBox ID="TxtRefDescription" runat="server" Width="279px" Height="112px" 
			Rows="4" TextMode="MultiLine"></asp:TextBox>
	</td>
</tr>
	<!--- <tr>
						<td>
							<asp:Label ID="lblStartDate" runat="server" Text="Start Date" />
							&nbsp;
							<asp:TextBox ID="txtStartDate" runat="server" Width="150px" ValidationGroup="Referrals" />
						</td>
						<td>
							<asp:Label ID="lblEndDate" runat="server" Text="End Date" />
							&nbsp;<asp:TextBox ID="txtEndDate" runat="server" Width="150px" ValidationGroup="Referrals" />&nbsp;
							<span style="font-size: 10pt; font-family: Arial">mm/dd/yyyy &nbsp; </span>
						</td>
					</tr>
					<tr>
						<td>
							<asp:RequiredFieldValidator ID="Date1Validator" runat="server" ControlToValidate="txtStartDate"
								Display="Dynamic" ErrorMessage="Required Field!" SetFocusonerror="True" ValidationGroup="Referrals"></asp:RequiredFieldValidator>
							<asp:RegularExpressionValidator ID="Date1ExpValidator" runat="server" ControlToValidate="txtStartDate"
								Display="Dynamic" ErrorMessage="Incorrect Format: mm/dd/yyyy" SetFocusonerror="True"
								ValidationExpression="^([1-9]|0[1-9]|1[012])[- /.]([1-9]|0[1-9]|[12][0-9]|3[01])[- /.][0-9]{4}$"
								ValidationGroup="Referrals"></asp:RegularExpressionValidator></td>
						<td>
							<asp:RequiredFieldValidator ID="Date2Validator" runat="server" ControlToValidate="txtEndDate"
								Display="Dynamic" ErrorMessage="Required Field!" SetFocusonerror="True" ValidationGroup="Referrals"></asp:RequiredFieldValidator>
							<asp:RegularExpressionValidator ID="Date2ExpValidator" runat="server" ControlToValidate="txtEndDate"
								Display="Dynamic" ErrorMessage="Incorrect Format: mm/dd/yyyy" SetFocusonerror="True"
								ValidationExpression="^([1-9]|0[1-9]|1[012])[- /.]([1-9]|0[1-9]|[12][0-9]|3[01])[- /.][0-9]{4}$"
								ValidationGroup="Referrals"></asp:RegularExpressionValidator></td>
					</tr> --->
<tr>
	<td style="width: 1px">
	</td>
	<td style="width: 136px">
	</td>
	<td>
		&nbsp;</td>
	</tr>
<tr>
	<td style="width: 1px">
	</td>
	<td style="width: 136px">
		<asp:Label ID="hidstatus" runat="server" CssClass="text" Visible="False"></asp:Label></td>
	<td>
		<asp:Button ID="cmdSubmitRef" runat="server" Width="188px" onclick="cmdSubmitRef_Click"
			Text="Submit Referral Information" ValidationGroup="Referrals" />&nbsp;
		<asp:Label ID="lblUserMessage" runat="server" ForeColor="Red"></asp:Label>
	</td>
	</tr>
	<tr>
		<td style="width: 1px">
		</td>
		<td style="width: 136px">
		</td>
		<td>
			&nbsp;</td>
	</tr>
	<tr>
		<td colspan="3" rowspan="2">
			<span class="notices" style="color: #ff0000">* Fields are required.<br />Please complete all required fields before submitting.</span>
	</td>
	</tr>
</table>
</asp:View>
<asp:View ID="View2" runat="server">
	<asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
		AutoGenerateColumns="False" EmptyDataText="No referrals in the database." 
		PageSize="50" SkinID="gvClearSkin" Width="600px" OnRowDataBound="GridView1_RowDataBound"  
		onrowdeleted="GridView1_RowDeleted" OnRowDeleting="GridView1_RowDeleting">
		<Columns>
		<asp:BoundField DataField="refid" Visible="False" />
		<asp:BoundField DataField="reffirstname" HeaderText="First Name" />
		<asp:BoundField DataField="reflastname" HeaderText="Last Name" />
		<asp:HyperLinkField DataNavigateUrlFields="refid" 
			DataNavigateUrlFormatString="~\admin\default.aspx?ld=refDirectory&amp;refid={0}" 
			DataTextField="reffirmname" HeaderText="Firm Name" />
		<asp:BoundField DataField="refspecialty" HeaderText="Specialty" />
		<asp:BoundField DataField="refstate" HeaderText="State" />   
	<asp:TemplateField  HeaderText="Select">		 
		<ItemTemplate>
<asp:LinkButton ID="LinkButton1" CommandArgument='<%# Eval("refid") %>' CommandName="Delete" 
runat="server">Delete</asp:LinkButton>
	<!---  or
	<asp:LinkButton ID="LinkButton2" CommandArgument='<%# Eval("refid") %>' CommandName="Edit" 
	runat="server">Edit</asp:LinkButton> --->
</ItemTemplate>
</asp:TemplateField>
		</Columns>
	</asp:GridView>
</asp:View>
<asp:View ID="View3" runat="server">
<div width="auto" style="height: 45px">
	<table id="EditRefer" border="0">
	
		<asp:DropDownList ID="cboChooseRef" runat="server" 
			DataSourceID="SqlDataSource1" 
			onselectedindexchanged="DropDownList1_SelectedIndexChanged" 
			AutoPostBack="True">
		</asp:DropDownList>
		<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
			ConnectionString="<%$ ConnectionStrings:PLNIndexConnectionString %>" 
			SelectCommand="SELECT [reffirstname], [reflastname] FROM [tbl_ReferralDirectory]">
		</asp:SqlDataSource>
	
	</table>
	<br />
	<asp:Label ID="Label1" runat="server" Text="Now Editing Referral:"></asp:Label><asp:Label ID="EditRefID" runat="server" Text=""></asp:Label><br />
	<asp:TextBox ID="EditRefFirst" runat="server" Width="236px"></asp:TextBox>
	<br />
	<asp:TextBox ID="EditRefLast" runat="server" Width="236px"></asp:TextBox><br />
	<asp:TextBox ID="EditRefFirm" runat="server" Width="236px"></asp:TextBox><br />
	<asp:TextBox ID="EditRefSpec" runat="server" Width="236px"></asp:TextBox><br />
	<asp:TextBox ID="EditRefAddress" runat="server" Width="236px"></asp:TextBox><br />
	<asp:TextBox ID="EditRefCity" runat="server" Width="236px"></asp:TextBox><br />
	<asp:TextBox ID="EditRefZipcode" runat="server" Width="236px"></asp:TextBox><br />
	<asp:TextBox ID="EditRefPhnArea" runat="server" Width="236px"></asp:TextBox><br />
	<asp:TextBox ID="EditRefPhnNum" runat="server" Width="236px"></asp:TextBox><br />
	<asp:TextBox ID="EditRefFaxArea" runat="server" Width="236px"></asp:TextBox><br />
	<asp:TextBox ID="EditRefFaxNum" runat="server" Width="236px"></asp:TextBox><br />
	<asp:TextBox ID="EditRefEmail" runat="server" Width="236px"></asp:TextBox><br />
	<asp:TextBox ID="EditRefWebsite" runat="server" Width="236px"></asp:TextBox><br />
	<asp:TextBox ID="EditRefDesc" runat="server" Width="236px"></asp:TextBox>
	
	<br />
	<br />
	<asp:Button ID="CmdRefEdit" runat="server" Text="Submit Changes" onclick="cmdEditRef_Click"
		 ValidationGroup="Referrals" Width="135px" />
	
	<br />


</div>
	
</asp:View>
</asp:MultiView>
</div>
</div>




Icludes/Private/adminReferralDirectory.ASCX.CS
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class includes__private_adminReferralDirectory : System.Web.UI.UserControl
{
	private static int deleteid;
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!IsPostBack)
		{
			cboStates.DataSource = functions.GetStates();
			cboStates.DataBind();
			cboStates.Items.Insert(0, "Please Select");		  
		}

		if (data.intRefID != 0)
		{
			bindReferrals();
		}
	}

	protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
	{
		int index = Int32.Parse(e.Item.Value);

		if ((index == 0) || (index == 1))
			MultiView1.ActiveViewIndex = index;

		switch (index)
		{ 
			case 0:
				cleanTextBoxes();
				break;
			case 1:
				GridView1.DataSource = directorylistings.GetDirectoryListings();
				GridView1.DataBind();
				break;
		}
	}

	protected void cmdSubmitRef_Click(object sender, EventArgs e)
	{
		string type = cboRTypes.SelectedItem.Value.Trim();
		string firstname = txtRefFirstName.Text.Trim();
		string lastname = txtRefLastName.Text.Trim();
		string firmname = txtRefFirmName.Text.Trim();
		string specialty = txtRefSpecialty.Text.Trim();
		string address = txtRefAddress.Text.Trim();
		string city = txtRefCity.Text.Trim();
		string state = cboStates.SelectedItem.Value.Trim();
		string postalcode = txtRefPostalCode.Text.Trim();
		string phoneareacode = txtRefPhoneNumberAreaCode.Text.Trim();
		string phonenumber = txtRefPhoneNumber.Text.Trim();
		string faxareacode = txtRefFaxNumberAreaCode.Text.Trim();
		string faxnumber = txtRefFaxNumber.Text.Trim();
		string emailaddy = txtRefEmailAddress.Text.Trim();
		string website = txtRefWebsite.Text.Trim().Replace("http://", "");
		string description = TxtRefDescription.Text.Trim();

		if (directorylistings.Insert(type, firstname, lastname, firmname, specialty, address, city, state, postalcode, phoneareacode, phonenumber, faxareacode, faxnumber, emailaddy, website, description) == true)
		{
			lblUserMessage.Text = "Referral added to the database.";
			cleanTextBoxes();
		}
		else
		{
			lblUserMessage.Text = "This request resulted in an error.";
		}	   
	}
	// Edit Referral Command Button
	protected void cmdEditRef_Click(object sender, EventArgs e)
	{
		private static int EditRefID;

		string etype = cboRTypes.SelectedItem.Value.Trim();
		string efirstname = EditRefFirst.Text.Trim();
		string elastname = EditRefLast.Text.Trim();
		string efirmname = EditRefFirm.Text.Trim();
		string especialty = EditRefSpec.Text.Trim();
		string eaddress = EditRefAddress.Text.Trim();
		string ecity = EditRefCity.Text.Trim();
		// string estate = cboStates.SelectedItem.Value.Trim();
		string epostalcode = EditRefZipcode.Text.Trim();
		string ephoneareacode = EditRefPhnArea.Text.Trim();
		string ephonenumber = EditRefPhnNum.Text.Trim();
		string efaxareacode = EditRefFaxArea.Text.Trim();
		string efaxnumber =

Was This Post Helpful? 0
  • +
  • -

#6 AFProgMan  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 80
  • Joined: 21-October 08

Re: Running Query From Dropdown Box

Posted 27 October 2008 - 08:49 AM

Keep getting these 2 errors.

Error 26 The name 'EditRefID' does not exist in the current context C:\Documents and Settings\kevin\My Documents\Visual Studio 2008\Projects\www.prisonlegalnews.org\www\App_Code\directorylistings.cs 176 61 C:\...\www\

Error 27 Cannot implicitly convert type 'System.Data.DataSet' to 'bool' C:\Documents and Settings\kevin\My Documents\Visual Studio 2008\Projects\www.prisonlegalnews.org\www\App_Code\directorylistings.cs 181 16 C:\...\www\
Was This Post Helpful? 0
  • +
  • -

#7 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Running Query From Dropdown Box

Posted 27 October 2008 - 09:35 AM

The problem lies with the following method:
	private static bool _getrefinfo(int EditRefId)
	{
		SqlConnection oConn;
		oConn = new SqlConnection(ConfigurationManager.AppSettings["connstring"]);

		string oString = "Select * From tbl_ReferralDirectory Where refid = @erefid";

		SqlCommand ocommand = new SqlCommand(oString, oConn);
		ocommand.Parameters.Add(new SqlParameter("@erefid", refid));
		DataSet DS = new DataSet();
		SqlDataAdapter oAdapter = new SqlDataAdapter(oString, oConn);
		oAdapter.Fill(DS, DataTable_Name);

		return DS;
	}


The function declaration states you will be returning a Boolean, but you are returning the DataSet. Also you are referencing "refid" as a parameter, but the parameter name being passed into the method is "EditRefId".

Modify the code to return a boolean or else a dataset depending on what you need. And fix the parameter to match the one passed into the method.
Was This Post Helpful? 0
  • +
  • -

#8 AFProgMan  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 80
  • Joined: 21-October 08

Re: Running Query From Dropdown Box

Posted 27 October 2008 - 10:17 AM

 private static DataSet _getrefinfo(int EditRefId)
	{
		string DataTable_Name = "tbl_ReferralDirectory";
		SqlConnection oConn;
		oConn = new SqlConnection(ConfigurationManager.AppSettings["connstring"]);

		string oString = "Select * From tbl_ReferralDirectory Where refid = @erefid";

		SqlCommand ocommand = new SqlCommand(oString, oConn);
		ocommand.Parameters.Add(new SqlParameter(EditRefId, "@erefid"));
		DataSet DS = new DataSet();  
		SqlDataAdapter oAdapter = new SqlDataAdapter(oString, oConn);  
		oAdapter.Fill(DS, DataTable_Name);

		return DS;
	}


I believe I spotted the same issue before and have corrected it. I also realized to i had the params backwards I think. @erefid is now being called instead of refid and I set it up as a DataSet instead of a bool.
Error 5 Cannot implicitly convert type 'System.Data.DataSet' to 'bool' C:\Documents and Settings\kevin\My Documents\Visual Studio 2008\Projects\www.prisonlegalnews.org\www\App_Code\directorylistings.cs 165 16 C:\...\www\
Error 6 The best overloaded method match for 'System.Data.SqlClient.SqlParameter.SqlParameter(string, System.Data.SqlDbType)' has some invalid arguments C:\Documents and Settings\kevin\My Documents\Visual Studio 2008\Projects\www.prisonlegalnews.org\www\App_Code\directorylistings.cs 176 33 C:\...\www\
Error 7 Argument '1': cannot convert from 'int' to 'string' C:\Documents and Settings\kevin\My Documents\Visual Studio 2008\Projects\www.prisonlegalnews.org\www\App_Code\directorylistings.cs 176 50 C:\...\www\
Error 8 Argument '2': cannot convert from 'string' to 'System.Data.SqlDbType' C:\Documents and Settings\kevin\My Documents\Visual Studio 2008\Projects\www.prisonlegalnews.org\www\App_Code\directorylistings.cs 176 61 C:\...\www\

Only to now receive these errors.


Is there a simpler way of doing what I am trying to do? Thank you for any help thus far.

This post has been edited by AFProgMan: 27 October 2008 - 10:24 AM

Was This Post Helpful? 0
  • +
  • -

#9 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Running Query From Dropdown Box

Posted 27 October 2008 - 11:11 AM

Can you post all the current code for directorylistings.cs?
Was This Post Helpful? 0
  • +
  • -

#10 AFProgMan  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 80
  • Joined: 21-October 08

Re: Running Query From Dropdown Box

Posted 27 October 2008 - 11:13 AM

Here is the code requested.

using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Logger;

/// <summary>
/// Summary description for directorylistings
/// </summary>
public class directorylistings : data
{
	private static string oConn = ConfigurationManager.AppSettings["connstring"];

	public static DataSet GetDirectoryListings()
	{
		return _getDirectoryListings();
	}
	private static DataSet _getDirectoryListings()
	{
		string oString = "Select reftype, refid ,reffirstname, reflastname, reffirmname, refspecialty, refaddress, refcity, refstate, refzipcode, refphoneareacode, refphonenumber, reffaxareacode, reffaxnumber, refemailaddress, refwebsiteaddress, refdescription "
			+ "From tbl_ReferralDirectory "
			+ "Order by refstate, refspecialty";

		string DataTable_Name = "tbl_ReferralDirectory";

		DataSet DS = new DataSet();
		SqlDataAdapter oAdapter = new SqlDataAdapter(oString, oConn);
		oAdapter.Fill(DS, DataTable_Name);

		return DS;
	}

	public static DataSet GetReferralByID(int refid)
	{
		return _getReferralByID(refid);
	}
	private static DataSet _getReferralByID(int refid)
	{
		string oConn = ConfigurationManager.AppSettings["connstring"];
		string oString = "Select refid, reftype, reffirstname, reflastname, reffirmname, refspecialty, refaddress, refcity, refstate, refzipcode, refphoneareacode, refphonenumber, reffaxareacode, reffaxnumber, refemailaddress, refwebsiteaddress, refdescription "
			+ "From tbl_ReferralDirectory "
			+ "Where refid = " + refid;

		string DataTable_Name = "tbl_ReferralDirectory";

		DataSet DS = new DataSet();
		SqlDataAdapter oAdapter = new SqlDataAdapter(oString, oConn);
		oAdapter.Fill(DS, DataTable_Name);
		return DS;
	}

	public static DataSet GetLatestDirectoryListings()
	{
		return _getLatestDirectoryListings();
	}
	private static DataSet _getLatestDirectoryListings()
	{
		string oString = "Select refid, reftype, reffirstname, reflastname, reffirmname, refspecialty, refaddress, refcity, refstate, refzipcode, refphoneareacode, refphonenumber, reffaxareacode, reffaxnumber, refemailaddress, refwebsiteaddress, refdescription "
			+ "From tbl_ReferralDirectory "
			+ "Order by refid desc";

		string DataTable_Name = "tbl_ReferralDirectory";

		DataSet DS = new DataSet();
		SqlDataAdapter oAdapter = new SqlDataAdapter(oString, oConn);
		oAdapter.Fill(DS, DataTable_Name);

		return DS;
	}

	public static bool Insert(string strtype, string strfirstname, string strlastname, string strfirmname, string strspecialty,
		string straddress, string strcity, string strstate, string strpostalcode, string strphoneareacode, string strphonenumber,
		string strfaxareacode, string strfaxnumber, string stremail, string strwebsite, string strdescription)
	{
		return _insert(strtype, strfirstname, strlastname, strfirmname, strspecialty, straddress, strcity,
				strstate, strpostalcode, strphoneareacode, strphonenumber, strfaxareacode, strfaxnumber, stremail, strwebsite, strdescription);
	}
	private static bool _insert(string strtype, string strfirstname, string strlastname, string strfirmname, string strspecialty,
		string straddress, string strcity, string strstate, string strpostalcode, string strphoneareacode, string strphonenumber,
		string strfaxareacode, string strfaxnumber, string stremail, string strwebsite, string strdescription)
	{

		SqlConnection oConn;
		oConn = new SqlConnection(ConfigurationManager.AppSettings["connstring"]);
		string oString = "Insert Into tbl_ReferralDirectory(reftype, reffirstname, reflastname, reffirmname, refspecialty, refaddress, refcity, refstate, refzipcode, refphoneareacode, refphonenumber, reffaxareacode, reffaxnumber, refemailaddress, refwebsiteaddress, refdescription) values(@type, @firstname, @lastname, @firm, @specialty, @address, @city, @state, @postalcode, @phoneareacode, @phonenumber, @faxareacode, @faxnumber, @email, @website, @description) ";

		SqlCommand ocommand = new SqlCommand(oString, oConn);
		ocommand.Parameters.Add(new SqlParameter("@type", strtype));
		ocommand.Parameters.Add(new SqlParameter("@firstname", strfirstname));
		ocommand.Parameters.Add(new SqlParameter("@lastname", strlastname));
		ocommand.Parameters.Add(new SqlParameter("@firm", strfirmname));
		ocommand.Parameters.Add(new SqlParameter("@specialty", strspecialty));
		ocommand.Parameters.Add(new SqlParameter("@address", straddress));
		ocommand.Parameters.Add(new SqlParameter("@city", strcity));
		ocommand.Parameters.Add(new SqlParameter("@state", strstate));
		ocommand.Parameters.Add(new SqlParameter("@postalcode", strpostalcode));
		ocommand.Parameters.Add(new SqlParameter("@phoneareacode", strphoneareacode));
		ocommand.Parameters.Add(new SqlParameter("@phonenumber", strphonenumber));
		ocommand.Parameters.Add(new SqlParameter("@faxareacode", strfaxareacode));
		ocommand.Parameters.Add(new SqlParameter("@faxnumber", strfaxnumber));
		ocommand.Parameters.Add(new SqlParameter("@email", stremail));
		ocommand.Parameters.Add(new SqlParameter("@website", strwebsite));
		ocommand.Parameters.Add(new SqlParameter("@description", strdescription));

		try
		{
			oConn.Open();
			ocommand.ExecuteNonQuery();
		}
		catch (Exception ee)
		{
			bool bReturnLog = false;
			ErrorLog.LogFilePath = "ErrorLogFile.txt";
			bReturnLog = ErrorLog.ErrorRoutine(false, ee);
			return false;
		}

		oConn.Close();
		oConn.Dispose();

		return true;
	}

	public static bool DeleteReferralByID(int intrefid)
	{
		return _deleteReferralByID(intrefid);
	}
	private static bool _deleteReferralByID(int intrefid)
	{

		SqlConnection oConn;
		oConn = new SqlConnection(ConfigurationManager.AppSettings["connstring"]);

		string oString = "Delete From tbl_ReferralDirectory Where refid = @refid";

		SqlCommand ocommand = new SqlCommand(oString, oConn);
		ocommand.Parameters.Add(new SqlParameter("@refid", intrefid));

		try
		{
			oConn.Open();
			ocommand.ExecuteNonQuery();
		}
		catch (Exception ee)
		{
			bool bReturnLog = false;
			ErrorLog.LogFilePath = "ErrorLogFile.txt";
			bReturnLog = ErrorLog.ErrorRoutine(false, ee);
			return false;
		}

		oConn.Close();
		oConn.Dispose();

		return true;
	}
	
	// GetRefInfo block

	public static DataSet GetRefInfo(int EditRefID)
	{
		return _getrefinfo(EditRefID);
	}
	private static DataSet _getrefinfo(int EditRefId)
	{
		string DataTable_Name = "tbl_ReferralDirectory";
		SqlConnection oConn;
		oConn = new SqlConnection(ConfigurationManager.AppSettings["connstring"]);

		string oString = "Select * From tbl_ReferralDirectory Where refid = EditRefID";

		SqlCommand ocommand = new SqlCommand(oString, oConn);
		ocommand.Parameters.Add(new SqlParameter(EditRefId, "@erefid"));
		DataSet DS = new DataSet();  
		SqlDataAdapter oAdapter = new SqlDataAdapter(oString, oConn);  
		oAdapter.Fill(DS, DataTable_Name);

		return DS;
	}

	public static bool Insert(string erefid, string estrtype, string estrfirstname, string estrlastname, string estrfirmname, string estrspecialty,
		string estraddress, string estrcity, string estrstate, string estrpostalcode, string estrphoneareacode, string estrphonenumber,
		string estrfaxareacode, string estrfaxnumber, string estremail, string estrwebsite, string estrdescription)
	{
		return _insert(erefid, estrtype, estrfirstname, estrlastname, estrfirmname, estrspecialty, estraddress, estrcity,
				estrstate, estrpostalcode, estrphoneareacode, estrphonenumber, estrfaxareacode, estrfaxnumber, estremail, estrwebsite, estrdescription);
	}
	private static bool _insert(string erefid, string estrtype, string estrfirstname, string estrlastname, string estrfirmname, string estrspecialty,
		string estraddress, string estrcity, string estrstate, string estrpostalcode, string estrphoneareacode, string estrphonenumber,
		string estrfaxareacode, string estrfaxnumber, string estremail, string estrwebsite, string estrdescription)
	{

		SqlConnection oConn;
		oConn = new SqlConnection(ConfigurationManager.AppSettings["connstring"]);
		string oString = "Select * From tbl_ReferralDirectory(refid, reffirstname, reflastname, reffirmname, refspecialty, refaddress, refcity, refstate, refzipcode, refphoneareacode, refphonenumber, reffaxareacode, reffaxnumber, refemailaddress, refwebsiteaddress, refdescription)";


		SqlCommand ocommand = new SqlCommand(oString, oConn);
		//ocommand.Parameters.Add(new SqlParameter("@etype", estrtype));
		ocommand.Parameters.Add(new SqlParameter("@erefid", erefid));
		ocommand.Parameters.Add(new SqlParameter("@efirstname", estrfirstname));
		ocommand.Parameters.Add(new SqlParameter("@elastname", estrlastname));
		ocommand.Parameters.Add(new SqlParameter("@efirm", estrfirmname));
		ocommand.Parameters.Add(new SqlParameter("@especialty", estrspecialty));
		ocommand.Parameters.Add(new SqlParameter("@eaddress", estraddress));
		ocommand.Parameters.Add(new SqlParameter("@ecity", estrcity));
		ocommand.Parameters.Add(new SqlParameter("@estate", estrstate));
		ocommand.Parameters.Add(new SqlParameter("@epostalcode", estrpostalcode));
		ocommand.Parameters.Add(new SqlParameter("@ephoneareacode", estrphoneareacode));
		ocommand.Parameters.Add(new SqlParameter("@ephonenumber", estrphonenumber));
		ocommand.Parameters.Add(new SqlParameter("@efaxareacode", estrfaxareacode));
		ocommand.Parameters.Add(new SqlParameter("@efaxnumber", estrfaxnumber));
		ocommand.Parameters.Add(new SqlParameter("@eemail", estremail));
		ocommand.Parameters.Add(new SqlParameter("@ewebsite", estrwebsite));
		ocommand.Parameters.Add(new SqlParameter("@edescription", estrdescription));

		try
		{
			oConn.Open();
			ocommand.ExecuteNonQuery();
		}
		catch (Exception ee)
		{
			bool bReturnLog = false;
			ErrorLog.LogFilePath = "ErrorLogFile.txt";
			bReturnLog = ErrorLog.ErrorRoutine(false, ee);
			return false;
		}

		oConn.Close();
		oConn.Dispose();

		return true;
	}
}


Was This Post Helpful? 0
  • +
  • -

#11 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Running Query From Dropdown Box

Posted 27 October 2008 - 12:45 PM

The following line needs to have the parameter being used added to the query inside the _getrefinfo function.

This:
string oString = "Select * From tbl_ReferralDirectory Where refid = EditRefID";  

Should be this:
string oString = "Select * From tbl_ReferralDirectory Where refid = @erefid";  

Was This Post Helpful? 1
  • +
  • -

#12 AFProgMan  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 80
  • Joined: 21-October 08

Re: Running Query From Dropdown Box

Posted 28 October 2008 - 09:25 AM

I did not use your exact method but you helped me understand what i was doign wrong I realized there was already the function that i needed created. So i just called that function with my param edtrefid that i have set up as static pulling the REFID from the table on dropdown change.

I then have all of the fields being filled individually. Works like a charm.

Thank you
Was This Post Helpful? 0
  • +
  • -

#13 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Running Query From Dropdown Box

Posted 28 October 2008 - 09:34 AM

Glad I could be of assistance, even in an indirect way.
Was This Post Helpful? 0
  • +
  • -

#14 AFProgMan  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 80
  • Joined: 21-October 08

Re: Running Query From Dropdown Box

Posted 28 October 2008 - 01:30 PM

because I am so rusty and especially not familiar with .net/c# over anything else, for the most part thats where I run into trouble. Just noticing the little things and understanding the nomenclature.

Just the second set of eyes always helps. Thanks again.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1