Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Joining data from a local datatable and a database table
Message
De
19/05/2007 10:49:24
 
 
À
19/05/2007 03:47:20
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
01226621
Message ID:
01227034
Vues:
12
Joaquim,

You definitely need to handle this with a Stored Proc and pass your list in as one Parameter.

In your Stored Proc, there are a couple ways to handle this.

Kevin Goff has a solution at this Message #1220992 ... he uses an XML approach. In this approach your Parameter would be an XML string (assuming you're using SQL Server 2005).

Another way to handle it is to use dynamic SQL in your Stored Proc with your parameter being the comma-delimited list, something like this:
declare @SelectStatement varchar(100)

Set @SelectStatement = 'select unidade, numero, date ' +
   'from _dsa_ihs_table ' +
   'where unidade in (' + @SParameter + ') ' +
   'order by unidade' 

execute (@SelectStatement)
~~Bonnie

>Thank you Viv, but i don't know how many parameters i need. That's the reason i don't send the parameter list separately.
>The user creates a list of codes, and i send this list as parameters to the database.
>
>One solution would be creating a memory DataTable internally, and then join the DataTable to the Database table. Something like this:
>
>
>DataTable dt = new DataTable("Table1");
>dt.Columns.Add("unidade");
>DataRow dr = dt.NewRow();
>dr["unidade"]= "1234";
>dt.Rows.Add(dr);
>dt.AcceptChanges();
>.
>.
>.
>dr["unidade"]= "9999";
>dt.Rows.Add(dr);
>dt.AcceptChanges();
>
>
>Once i had this table i could create a select string like this:
>
>
>SelectString = "select a.unidade, a.numero, a.date " +
>  "from _dsa_ihs_table a, 'Table1' b" +
>  "where a.unidade = b.unidade " +
>  "order by a.unidade" ;
>
>
>But for that i know there's no way to do this. Or there is?
>
>Joaquim
>
>
>>Hi,
>>
>>
>>You'd need to pass the parameters in seperately:
>>  "where unidade in (?,?,?,?, etc) " +"
which isn't particularly practical. Maybe pass the SParameter to a SP instead?
>>Regards,
>>Viv
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform