Showing posts with label form. Show all posts
Showing posts with label form. Show all posts

Tuesday, March 27, 2012

binding textbox text to a database field

hello

is it possible to to bind a single field from a database table to a textbox.

I am trying to open a web form with five textboxes on it. When it loads is it possible to have the textboxes filled with a different field from a row in a database, selected with a sql statment.

Thanks in advance NubNub

Wrong Forum.|||

Yes, that is quite possible.

But you will get better assistance if you post your question in one of the .NET ASP related forums.

sql

Binding error

Hi all

I have a form view which uses a SQL data source control to retrieve it's data from the sql express database

the form view is used for view,edit,delete and insert data into the database

in the insert mode I have two dropdownlists, where the second one is depending on the first one to retrieve the correct data from the data baseBUT

when selecting a value in the first dropdownlist it give me the following erro:

Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.

Please How can do this

any help is appriciated

bye

You cannt do this using this method. There are many work arrounds out there, but the easiest I believe is the CascadingDropDown control which is part of the AJAX.NET Control Toolkit.

http://www.asp.net/ajax/ -- Install the AJAX.NET FRAMEWORK AND configure your site to use it.

You will need to:

1.) First Create a Web Service Class like as followed:

using System;using System.Web;using System.Collections;using System.Configuration;using System.Web.Services;using System.Web.Services.Protocols;using System.Collections.Generic;using AjaxControlToolkit;using System.Data;using System.Data.SqlClient;using System.Web.Script.Services;/// <summary>/// Cascading DropDownList AjaxControlToolkit Web Service/// </summary>[WebService(Namespace ="http://tempuri.org/")][WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)][System.Web.Script.Services.ScriptService]public class DataService : System.Web.Services.WebService { private string connectionString =ConfigurationManager.ConnectionStrings["CarrierDBConnectionString"].ConnectionString; public DataService () {} [WebMethod] [System.Web.Script.Services.ScriptMethod()] public CascadingDropDownNameValue[] GetCarriers(string knownCategoryValues, string category) { List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>(); using (SqlConnection conn = new SqlConnection(connectionString)) { using (SqlCommand cmd = new SqlCommand("CARRIER_SELECT_ALL", conn)) { cmd.CommandType = CommandType.StoredProcedure; conn.Open(); SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); while (dr.Read()) { values.Add(new CascadingDropDownNameValue((string)dr["NAME"], dr["ID"].ToString())); } } } return values.ToArray(); } [WebMethod] [System.Web.Script.Services.ScriptMethod()] public CascadingDropDownNameValue[] GetSubsidiariesByCarrierID(string knownCategoryValues, string category) { List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>(); using (SqlConnection conn = new SqlConnection(connectionString)) { using (SqlCommand cmd = new SqlCommand("CARRIER_SELECT_SUBSIDIARY_BYID", conn)) { string[] categoryValues = knownCategoryValues.Split(':', ';'); int id = Convert.ToInt32(categoryValues[1]); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@.id",id); conn.Open(); using (SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)) { if (dr.HasRows) { while (dr.Read()) { values.Add(new CascadingDropDownNameValue((string)dr["NAME"], dr["ID"].ToString())); } } } } }return values.ToArray(); }}

2.) Create the Actual Web Service

Click on the Project in the 'Solution Explorer' and 'Add New Item' and then select Web Service (for instance in this example: DataService.asmx)

3.) Hook up your ajax controls and dropdownlist


<asp:UpdatePanel ID="updatePnlInsert" runat="server">
<ContentTemplate>
<asp:DropDownList ID="ddlCarrierInsert" runat="server" AutoPostBack="True" Width="100%" DataSourceID="sqldsCarriersInsert" DataTextField="NAME" DataValueField="ID" SelectedValue='<%# Eval("CARRIER_ID") %>' AppendDataBoundItems="true">
<asp:ListItem Value="" Text="<select carrier>" />
</asp:DropDownList>
<br />
<asp:SqlDataSource ID="sqldsCarriersInsert" runat="server" ConnectionString="<%$ ConnectionStrings:CarrierDBConnectionString %>"
SelectCommand="CARRIER_SELECT_ALL" SelectCommandType="StoredProcedure" />

<asp:DropDownList ID="ddlSubInsert" runat="server" Width="100%" /><br />
<cc1:CascadingDropDown ID="cddCarrierInsert" runat="server"
TargetControlID="ddlSubInsert"
ParentControlID="ddlCarrierInsert"
Category="CARRIER"
LoadingText="[Loading Subsidiaries...]"
PromptText="<select subsidary>"
ServiceMethod="GetSubsidiariesByCarrierID"
ServicePath="DataService.asmx"
SelectedValue='<%# Eval("SUBSIDIARY_ID") %>'>
</cc1:CascadingDropDown>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlCarrierInsert" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>

Hope this helps.

Binding a DataSource Table column to a form object (RadioButtons)

Hi,

I have a little question. I have an application which interfaces with a SQL Express Database. On a form, I want to bind a control which is made of several Radio buttons to a table column which is in fact a varchar(1). This is the picture:

Table column: OptVisualRpt varchar(1)

Screen control: 2 radio buttons

rb_VisRPTbImp_O for "yes"

rb_VisRPTbImp_N for "no"

I'm really scratching my head as how I can bind a single table column to my radio buttons controls. I think that I just can't this way but rather have to use an intermediate variable or control.

Solution 1?

I thought of using a local variable that I would set to "y" or "n" following "CheckedChanged" events fired from radio buttons but I don't know how to bind this variable to my table column.

Solution 2?

I thought of placing a hidden text control into my form, which one would be binded to my table column, that I would also set to "y" or "n" following "CheckedChanged" events fired from radio buttons.

Any of these solutions which would be feasible or any more neat way to do it?

Many thanks in advance,

Stphane

Hi again,

Finally sounds that last night I could solve my problem by myself. Let me explain.

1- I first got rid of the "Binding source". I removed following lines:

=> private: System::Windows::Forms::BindingSource ^ InfoBaseBindingSource;

=> this->InfoBaseBindingSource = (gcnew System::Windows::Forms::BindingSource(this->components));

=> (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->InfoBaseBindingSource))->BeginInit();

=> //
// InfoBaseBindingSource
//

this->InfoBaseBindingSource->DataMember = L"InfoBase";
this->InfoBaseBindingSource->DataSource = this->Test_ADODataSet;

=> (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->InfoBaseBindingSource))->EndInit();

2- At the same time, for every field control that were fed by it, I removed from code the following line (here is an example):

this->ID_Compagnie->DataBindings->Add((gcnew System::Windows::Forms::Binding(L"Text", this->InfoBaseBindingSource, L"Identification", true)));

3- I then changed the Form1_Load routine for the following:

this->InfoBaseTableAdapter->Fill(this->Test_ADODataSet->InfoBase);

DataTable ^ Dt_Infobase = this->Test_ADODataSet->Tables["InfoBase"];
if(Dt_Infobase != nullptr)
{
array<DataRow^> ^ Rw_InfoBase = Dt_Infobase->Select();
if(Rw_InfoBase->Length != 0)
{
this->ID_Compagnie->Text = Rw_InfoBase[0]["Identification"]->ToString();
this->Adr_Compagnie->Text = Rw_InfoBase[0]["Adresse"]->ToString();
...

==> Example of loading a masked text box

// Affichage et rectification du format du Code Postal/ZipCode

if(String::Compare(this->Pays_Compagnie->Text,"Canada") == 0)
{
this->CPZip_Compagnie->Mask = ">L0>L 0>L0";
this->Pnl_VSZCode->Hide();
}
else
{
this->Pnl_VSZCode->Show();
if(this->CPZip_Compagnie->Text->Length > 5)
{
this->VScrl_ZCode->Value = 1;
this->CPZip_Compagnie->Mask = "99999";
}
else
{
this->VScrl_ZCode->Value = 0;
this->CPZip_Compagnie->Mask = "99999-9999";
}
}

this->CPZip_Compagnie->Text = Rw_InfoBase[0]["CodePostal_Zip"]->ToString();

...

==> Example of "loading" info vs a set of radio buttons

String ^ Logo_ModeAff = Rw_InfoBase[0]["LogoRpt_ModeAff"]->ToString();
if(Logo_ModeAff == "C")
{
this->rb_ModeAffLCoord->Checked = true;
this->rb_ModeAffLOnly->Checked = false;
}
else
{
this->rb_ModeAffLCoord->Checked = false;
this->rb_ModeAffLOnly->Checked = true;
}
}

4- I then changed the B_Accept_Click routine for the following:

I removed following sentences:

this->InfoBaseBindingSource->EndEdit();
this->InfoBaseTableAdapter->Update(this->Test_ADODataSet->InfoBase);
this->Test_ADODataSet->AcceptChanges();

And replaced them with following:

DataTable ^ Dt_Infobase = this->Test_ADODataSet->Tables["InfoBase"];
if(Dt_Infobase != nullptr)
{
array<DataRow^> ^ Rw_InfoBase = Dt_Infobase->Select();
if(Rw_InfoBase->Length == 0)
{
DataRow ^ NRw_InfoBase = Dt_Infobase->NewRow();

NRw_InfoBase["Identification"] = this->ID_Compagnie->Text;
...
==> Example of a "saving" info vs a set of radio buttons

if(this->rb_ModeAffLCoord->Checked == true)
NRw_InfoBase["LogoRpt_ModeAff"] = "C";
else
NRw_InfoBase["LogoRpt_ModeAff"] = "L";
...

Dt_Infobase->Rows->Add(NRw_InfoBase);
}
else
{
Rw_InfoBase[0]["Identification"] = this->ID_Compagnie->Text;
...
==> Example of a "replacing" info vs a set of radio buttons

if(this->rb_ModeAffLCoord->Checked == true)
Rw_InfoBase[0]["LogoRpt_ModeAff"] = "C";
else
Rw_InfoBase[0]["LogoRpt_ModeAff"] = "L";
...
}

this->InfoBaseTableAdapter->Update(this->Test_ADODataSet);
this->Test_ADODataSet->AcceptChanges();
}

5- I finally changed the B_Cancel_Click routine for the following:

I removed following sentences:

this->InfoBaseBindingSource->EndEdit();

This code is maybe not the best way to do it. If someone has any more proper way to do it, I would certainly appreciate to learn. My conclusion is that doing this binding process manually gives better results than relying on a BindingSource object.

Stphane

Bind message to a constraint check

I'm doing a migration form Sybase to Microsoft Sql Server 2005. On my sybase
datbase, I have some check constrainst. Thos contraints are linked (sybase
procedure sp_bindmsg) with specific messages in case that those constraint
are not followed.
Idon't know and don't find something equivalent on Sql Server.
Thanks for your help!You cannot bind a user defined message to system errors (like of you want to add a row to a
referencing table if a value doesn't exists in the referenced table).
Consider requesting the feature to sqlwish@.microsoft.com.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"valerie uzan" <valerieu@.srl.co.il> wrote in message
news:ed0ffe6febd048e98407c892029b9413@.ureader.com...
> I'm doing a migration form Sybase to Microsoft Sql Server 2005. On my sybase
> datbase, I have some check constrainst. Thos contraints are linked (sybase
> procedure sp_bindmsg) with specific messages in case that those constraint
> are not followed.
> Idon't know and don't find something equivalent on Sql Server.
> Thanks for your help!

Bind message to a constraint check

I'm doing a migration form Sybase to Microsoft Sql Server 2005. On my sybase
datbase, I have some check constrainst. Thos contraints are linked (sybase
procedure sp_bindmsg) with specific messages in case that those constraint
are not followed.
Idon't know and don't find something equivalent on Sql Server.
Thanks for your help!
You cannot bind a user defined message to system errors (like of you want to add a row to a
referencing table if a value doesn't exists in the referenced table).
Consider requesting the feature to sqlwish@.microsoft.com.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"valerie uzan" <valerieu@.srl.co.il> wrote in message
news:ed0ffe6febd048e98407c892029b9413@.ureader.com. ..
> I'm doing a migration form Sybase to Microsoft Sql Server 2005. On my sybase
> datbase, I have some check constrainst. Thos contraints are linked (sybase
> procedure sp_bindmsg) with specific messages in case that those constraint
> are not followed.
> Idon't know and don't find something equivalent on Sql Server.
> Thanks for your help!

Sunday, March 25, 2012

Bind message to a constraint check

I'm doing a migration form Sybase to Microsoft Sql Server 2005. On my sybase
datbase, I have some check constrainst. Thos contraints are linked (sybase
procedure sp_bindmsg) with specific messages in case that those constraint
are not followed.
Idon't know and don't find something equivalent on Sql Server.
Thanks for your help!You cannot bind a user defined message to system errors (like of you want to
add a row to a
referencing table if a value doesn't exists in the referenced table).
Consider requesting the feature to sqlwish@.microsoft.com.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"valerie uzan" <valerieu@.srl.co.il> wrote in message
news:ed0ffe6febd048e98407c892029b9413@.ur
eader.com...
> I'm doing a migration form Sybase to Microsoft Sql Server 2005. On my syba
se
> datbase, I have some check constrainst. Thos contraints are linked (sybase
> procedure sp_bindmsg) with specific messages in case that those constraint
> are not followed.
> Idon't know and don't find something equivalent on Sql Server.
> Thanks for your help!sql

Bind computed textbox value to database field

Hi all,

I have three textboxes in a form view

1- Qty textbox

2- price textbox

3-TotalPrice textbox which value is the result of multiplying the previous two values

and then I want to Bind() the third value to the totalprice field in the database

how can I do that??

(without making the database field as a computed column)

thanks for any help

1. What database?
2. What language?
3. How are you retrieving the value of the third textbox currently?
4. How are you performing data access? SqlDataSource controls? ADO.NET code in your code-behind? Custom business classes? Typed DataSets?

You really should provide more information so that people can help you. The answer to your question is very simple. You simply run an Insert statement against the database. However, I suspect that no one has bothered to reply so far because how you run the insert and in what language isn't clear from your post.

If you can work out what to do from the "run an Insert statement" answer, that's great. But if you want some sample code offered, help us to help you.Big Smile

|||

Hi

Thanks for reply,

1- SQL Express database

2- langauge= VB

3- I don't know (someone has made a visual basic 6 application and I don't have the source code of it so I am converting it into ASP.net)

4- I am using SQL data source control to select,update,insert and delete the records from the database

I want to make the third text box value as a result of multiplying the first two values

And then bind that value to the database

Thank you

|||

Frankly, I'm not sure about the need for a 3rd textbox. Your InsertCommand for the SqlDataSource should be something like "Insert Into mytable (price, quantity, total) Values (@.price, @.quantity, @.total)". You need 3 InsertParameters. The first 2 will be <asp:ControlParameters>, and the ControlID will be the textboxes for price and quantity. The third will be a straightforward <asp:parameter> of type Int32.

Create a SqlDataSource_Inserting event by selecting the datasource control in design view, then hit F4 to bring up the porperties. Double click the lightning bolt to bring up the events and double click the Inserting event. That will create code for handling the event. The code is straightofrward, something along the lines of:

Dim price As Integer = Convert.ToInt32(TextBox1.Text)
Dim qty As Integer = Convert.ToInt32(TextBox2.Text)
Dim total As Integer = price * qty

Then just add code to set the value of the plain parameter to the calculation:

SqlDataSource.InsertParameters("total").DefaultValue = total

Thursday, March 22, 2012

Binary or Byte data linked to Checkbox

Dear Group,
I'm using Access 2003 linked to an SQL Server data table via an ODBC
connection.
On one form I have several check boxes which want data mapped to a
TRUE/FALSE datatype. Is there a direct way to bind a checkbox to a
bit, a binary, or a tinyint? I've only been able to get it to work
with a smallint which is 2 bytes long.
Thanks,
Max
Arg. Access wants to insert -1 for true and 0 for false.
So sorry the type will need to support negative numbers.
Matt Neerincx [MSFT]
This posting is provided "AS IS", with no warranties, and confers no rights.
Please do not send email directly to this alias. This alias is for newsgroup
purposes only.
"Max Yaffe" <myaffe@.not.gamry.com> wrote in message
news:0f1ji1p22uleclnn5t4lka3vnta48bda3k@.4ax.com...
> Dear Group,
> I'm using Access 2003 linked to an SQL Server data table via an ODBC
> connection.
> On one form I have several check boxes which want data mapped to a
> TRUE/FALSE datatype. Is there a direct way to bind a checkbox to a
> bit, a binary, or a tinyint? I've only been able to get it to work
> with a smallint which is 2 bytes long.
> Thanks,
> Max

Binary or Byte data linked to Checkbox

Dear Group,
I'm using Access 2003 linked to an SQL Server data table via an ODBC
connection.
On one form I have several check boxes which want data mapped to a
TRUE/FALSE datatype. Is there a direct way to bind a checkbox to a
bit, a binary, or a tinyint? I've only been able to get it to work
with a smallint which is 2 bytes long.
Thanks,
MaxArg. Access wants to insert -1 for true and 0 for false.
So sorry the type will need to support negative numbers.
Matt Neerincx [MSFT]
This posting is provided "AS IS", with no warranties, and confers no rights.
Please do not send email directly to this alias. This alias is for newsgroup
purposes only.
"Max Yaffe" <myaffe@.not.gamry.com> wrote in message
news:0f1ji1p22uleclnn5t4lka3vnta48bda3k@.
4ax.com...
> Dear Group,
> I'm using Access 2003 linked to an SQL Server data table via an ODBC
> connection.
> On one form I have several check boxes which want data mapped to a
> TRUE/FALSE datatype. Is there a direct way to bind a checkbox to a
> bit, a binary, or a tinyint? I've only been able to get it to work
> with a smallint which is 2 bytes long.
> Thanks,
> Max

Tuesday, March 20, 2012

big problem with data conversion

Dear colleagues, I have a big problem with data conversion. For example, on my Windows form (C#) i have one text box and in my table I have field type float. When I use following conversion or casting:

float i = (float)Convert.ToDouble(textBox1.Text);

and insert number 12,3 in my table I have following number 12.30000000000032324!

What I must to do with this conversion and have in my table number 12,3?

Hi,

although this is not a C# forum, you should take a look at the Help for a more precise datatype than float.

http://msdn2.microsoft.com/en-us/library/b1e65aza.aspx

In addition see the float definition in the BOL for more information about float in SQL Server.

You might want to have a look on the decimal type instead.

HTH, Jens K. Suessmeyer.

http://www.sqlserver2005.de

Thursday, March 8, 2012

BI Application & SQL Server Express Edition

I was wondering whether anyone could enlighten me:
We currently build DB apps with a jet engine DB and c# Windows Form front end.
We wish to develop client windows form apps that can be installed on client PCs, which will have an SQL Server back-end and windows form Front End. However the apps we want to build are BI application using cubes we generate (in Analysis Services).
Now am I right in saying that we cannot develop an application that can be installed on a customer site that would include SQL Server Expres AND have the BI functionality? We wish to build a tool for customers that allows them to slice and dice data we provide

It is a pre-requisite that we must not assume that they have access to the internet and we cannot assume that they have an SQL Server which we could automatically install our product onto (to allow for BI functionailty).
So far all the tools we seen and the end-to-end applications, tend to refer to a pre-exisitng installation of SQL Server (with Analysis Services) e.g. Programmming SQL Server 2005 - Microsoft Press.
We need to create custom apps that can "stand alone". Is there any solution?

First. Analysis Services component of the Microsoft SQL Server 2005 product is not part of the Express Edition. It is part of any other edition of SQL Server ( except may be for the mobile edition )

This doesnt mean you cannot install Express and Standard editions of SQL Server side.

Now there is wide range of functionality supported by Analysis Services. You have to figure out what you would like to provide your users with.

Edward.
--
This posting is provided "AS IS" with no warranties, and confers no rights.

Sunday, February 19, 2012

Best way to search for all records (Using a Case Statement in a SP)

I have a form with a dropdown or combo box, the user can select <All>
or pick a user name. If they pick a user name my where clause works
fine, buts what's the best way to write "Select All" if they choose
the <All
This is what I have so far, but I don't think I should be using the
LIKE operator.

WHERE tblCase.qarep LIKE CASE @.myqarep WHEN '<All>' THEN '%' ELSE
@.myqarep END
and tblOffice.officecode LIKE CASE @.myoffice WHEN -1 THEN '%' ELSE
@.myoffice END

thanks for your help!!On 13 Sep 2004 10:47:21 -0700, PaulMac wrote:

>I have a form with a dropdown or combo box, the user can select <All>
>or pick a user name. If they pick a user name my where clause works
>fine, buts what's the best way to write "Select All" if they choose
>the <All>
>This is what I have so far, but I don't think I should be using the
>LIKE operator.
>WHERE tblCase.qarep LIKE CASE @.myqarep WHEN '<All>' THEN '%' ELSE
>@.myqarep END
> and tblOffice.officecode LIKE CASE @.myoffice WHEN -1 THEN '%' ELSE
> @.myoffice END
>thanks for your help!!

Hi Paul,

You could use this:

WHERE tblCase.qarep = CASE @.myqrep
WHEN '<All>' THEN tblCase.qarep
ELSE @.myqrep
END
AND tblOffice.officecode = CASE @.myoffice
WHEN -1 THEN tblOffice.officecode
ELSE @.myoffice
END

An alternative that's a bit more work to create but that will probably
perform better is to write different versions of the query; use IF to
select which search arguments are set to All and which are set to a value
and then execute the correct version of the query.

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)|||PaulMac (paulmac106@.hotmail.com) writes:
> I have a form with a dropdown or combo box, the user can select <All>
> or pick a user name. If they pick a user name my where clause works
> fine, buts what's the best way to write "Select All" if they choose
> the <All>
> This is what I have so far, but I don't think I should be using the
> LIKE operator.
> WHERE tblCase.qarep LIKE CASE @.myqarep WHEN '<All>' THEN '%' ELSE
> @.myqarep END
> and tblOffice.officecode LIKE CASE @.myoffice WHEN -1 THEN '%' ELSE
> @.myoffice END

Since it's a combo, LIKE appears to be a bit of overkill. The normal
procedure is to pass NULL when you want all:

WHERE (qarep = @.myqarep OR @.myqarep IS NULL)
AND (officecode = @.myoffice OR @.myoffice IS NULL)

But of course this works too:

WHERE (qarep = @.myqarep OR @.myqarep = '<All>')
AND (officecode = @.myoffice OR @.myoffice = -1)

At least as long as you don't localize the string...

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||I will not suggest putting a CASE command in the WHERE clause, you may
just want to use "if" control statement to separate two code blocks
which will be more efficient at database level.

IF Boolean_expression
{ sql_statement | statement_block }
[
ELSE
{ sql_statement | statement_block } ]

paulmac106@.hotmail.com (PaulMac) wrote in message news:<1ee8a467.0409130947.4f608eba@.posting.google.com>...
> I have a form with a dropdown or combo box, the user can select <All>
> or pick a user name. If they pick a user name my where clause works
> fine, buts what's the best way to write "Select All" if they choose
> the <All>
> This is what I have so far, but I don't think I should be using the
> LIKE operator.
> WHERE tblCase.qarep LIKE CASE @.myqarep WHEN '<All>' THEN '%' ELSE
> @.myqarep END
> and tblOffice.officecode LIKE CASE @.myoffice WHEN -1 THEN '%' ELSE
> @.myoffice END
> thanks for your help!!|||Hi Hugo

That worked perfectly...Thank You!!

Hugo Kornelis <hugo@.pe_NO_rFact.in_SPAM_fo> wrote in message news:<3e6ck0dsnb7m8pvq95ps7ceu2nu0lj353t@.4ax.com>...
> On 13 Sep 2004 10:47:21 -0700, PaulMac wrote:
> >I have a form with a dropdown or combo box, the user can select <All>
> >or pick a user name. If they pick a user name my where clause works
> >fine, buts what's the best way to write "Select All" if they choose
> >the <All>
> >This is what I have so far, but I don't think I should be using the
> >LIKE operator.
> >WHERE tblCase.qarep LIKE CASE @.myqarep WHEN '<All>' THEN '%' ELSE
> >@.myqarep END
> > and tblOffice.officecode LIKE CASE @.myoffice WHEN -1 THEN '%' ELSE
> > @.myoffice END
> >thanks for your help!!
> Hi Paul,
> You could use this:
> WHERE tblCase.qarep = CASE @.myqrep
> WHEN '<All>' THEN tblCase.qarep
> ELSE @.myqrep
> END
> AND tblOffice.officecode = CASE @.myoffice
> WHEN -1 THEN tblOffice.officecode
> ELSE @.myoffice
> END
> An alternative that's a bit more work to create but that will probably
> perform better is to write different versions of the query; use IF to
> select which search arguments are set to All and which are set to a value
> and then execute the correct version of the query.
> Best, Hugo

Sunday, February 12, 2012

Best way to do a free text search

HiI have a .net 2 website that works from a sql 2000 db. I am building a form that will allow the user to type in any search criteria and based on their input I need to produce some results (that's the simplest way to put it)I will need to search various parts of my db to find similar sounding information, I was just wondering what is the best way to do this. I had the following thoughts1) Search columns using Soundex tsql function (but not sure how good this is?)2) Remove all noise words from user input (eg, and, or, the etc...) and then use a regular expression to search the fields in the dbAlternatively are their some third party components to do can do this for me Many thanks in advance

You can full text search enable the database, and create a full text index on the column in the table you want to search. Then you will be able to search any word that appears inside that column. Here are a couple of links that might be helpful to you.

http://www.databasejournal.com/features/mssql/article.php/3441981

http://www.wherecanibuyit.co.uk/ASP/full-text-search.html

http://msdn2.microsoft.com/en-us/library/ms177652.aspx

|||

Hi

Thanks for that, it was a great help

I have noticed that their is a RowNumber method in SQL 2005, is their any way to do this functionality in SQL 2000

One method I thought of was to put the data in temp table and loop through each record and give it a number, and then pull out 10 records at a time as the user pages through.

Are their any other ways I could do this.

Many thanks in advance

|||

The short answer is yes. You may want to search for articles on Custom Paging with SQL Server 2000. There are ways to do it, but they are not as simple or clean as the ROW_NUMBER() function. Here is an article to get you started.

http://www.4guysfromrolla.com/webtech/042606-1.shtml