Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Connecting to VFP Data in ASP.NET
Message
 
À
02/01/2006 09:17:38
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
Information générale
Forum:
Visual FoxPro
Catégorie:
Visual FoxPro et .NET
Divers
Thread ID:
01072118
Message ID:
01082512
Vues:
44
Cetin, I've got the sqlserver vers of this project up and running using:
SqlDataSource1.SelectCommand = "SELECT [title], [type_dish],[recipe_id] FROM [dish] WHERE [title] LIKE '%' + @box1 + '%'".
It's pretty simple. But to pass a var from a textbox (ie @box1) in the vfpoledb scenario involves all that code you supplied? To what language does your "selectCmd.CreateParameter" belong? I try do do as much in the code behind as possible. Also, what is '%{0}%', is this some reserved search syntax?




>Tim,
>If it works with any backend then would work with VFP too (I doubt it would work however).
>Here is what I mean to be more clear:
>You're constructing the full SQL string (it is not parametric ADO.Net query). Yours look like to be the same as writing (correcting typo closing parentheses):
>
>String.Format("SELECT title, type_dish FROM dish WHERE title LIKE '%{0}%'",box1)
>
>and would send to backend something like:
>SELECT title, type_dish FROM dish WHERE title LIKE '%sometitle%'
>
>Also note that:
>vDataSource2.SelectCommand expects a Command object not a string. ie:
>vDataSource2.SelectCommand = new OleDbCommand( "...", connection)
>
>like '%sometitle%'
>
>doesn't work the same way in VFP and SQL server. SQL server case sensitivity could be adjusted with a single setting for all SQLs while in VFP it's case sensitive (ie: it would miss SomeTitle). In other words accept there are major differences between VFP and SQL server SQL. It's an illusion that you could write SQL that's compatible with any backend (well you might but a very hard thing to do IMHO). You can come close to it using SQL and functions that are available in both (ie: SQL server doesn't have alltrim() but have rtrim() and ltrim() when combined same as alltrim).
>
>Next try to use parameters collection instead of formatting the whole string. ie:
>
>
>strSelect = "SELECT title, type_dish FROM dish WHERE title LIKE ?"
>
>
>VFP doesn't support @box style named parameters but only positional parameters (that's first parameter added to the collection correspond to first ? -parameter placeholder- in SQL string). While SQL server supports both. So this would work with VFP or SQL server (not exact syntax, because I'm weak with VB and C# might confuse you):
>
>
>strSelect = "SELECT title, type_dish FROM dish WHERE title LIKE ?"
>selectCmd = new OleDbCommand( strSelect, connection )
>myTitle = selectCmd.CreateParameter('myTitle',OleDbType.Char)
>selectCmd.Parameters.Add(myTitle)
>vDataSource2.SelectCommand = selectCmd;
>
>myTitle.Value = "%SomeTitle%"
>' execute command and fill say a dataset
>myTitle.Value = "%AnotherTitle%"
>' execute command
>
>While building the whole string vs using parameters look similar they are not same. This is especially important if your parameter is a long string. Building the string would fail upon calling VFPOLEDB, parameterized one succeeds (check a recent thread about memo fields and ASP.Net in .Net forum - it also has a full C# sample).
>Cetin
>
>
>>Thanks again Cetin. If I'm going the vfp route, are there any other major differences in syntax from using SQLSERVER? My main concern is my selectcommand string. I have to form it according to VFP rules I assume.
>>I am having trouble with variables in vb.net and my statement as follows:
>>vDataSource2.SelectCommand = "SELECT title, type_dish FROM dish WHERE title LIKE '%' + @box1 + '%')"
>>Does vfp handle @variables like this do you know?
>>
>>
>>>Yes your updates/inserts will work OK.
>>>In VFP you could have a field named (for example-never do that) 'table'. ie:
>>>
>>>Create Table Table (Table i)
>>>For ix = 1 To 10
>>>  Insert Into Table (Table) Values (m.ix)
>>>Endfor
>>>Select Table From Table
>>>
As ugly as it gets but you can do it! Notice that I used keyword 'table' as a tablename, as well as a columnname in that table. In SQL server keywords are not allowed in this fashion. However still in SQL server you could do the same using angle brackets (which tells SQL server that it is a name rather than a keyword). ie:
>>>
>>>Create Table [Table] ([Table] i)
>>>For ix = 1 To 10
>>>  Insert Into [Table] ([Table]) Values (m.ix)
>>>Endfor
>>>Select [Table] From [Table]
>>>
In SQL server also you could have a field named "My field name with spaces in it" < g >. Again you could use such a field (not the only way):
>>>
>>>select [My field name with spaces in it] from [myTable]
>>>
>>>and SQL server knows you're referring to a single column. I have exagarated it a bit to show what it is for:)
>>>Cetin
>>>
>>>>Thank you !!! that did it! I never would have guessed that. What do the brackets mean in SQL server anyway? Since my data is in vfp, I wanted to phase out sql server. Will the updates, and inserts work in .NET 2 with VFPOLEDB ok?
>>>>
>>>>
>>>>>Oh this is 2.0, right? I don't have it here to test but at a glance this drew my attention:
>>>>>"SELECT [title], [type_dish] FROM [dish] ..."
>>>>>You're using VFPOLEDB so this string is evaluated by VFP's engine. While in SQL server and MSAccess you can use angle brackets for fieldnames, in VFP it has a special meaning. Under VFP angle brackets, double and single quotes all are used as string delimiters. IOW if you execute this SQL you'd get back N rows matching your where clause but all rows would have "title" and "type_dish" in it. Try:
>>>>>"SELECT title, type_dish FROM dish ..."
>>>>>
>>>>>Cetin
>>>>>
>>>>>
>>>>>>Sure can, here is one of the apps(at home) that is giving me the same exact type of prob at work. In VS.net, I can show table data just fine in the 'database explorer' tab.
>>>>>>
>>>>>>
>>>>>><body>
>>>>>>    <form id="form1" runat="server">
>>>>>>    <div>
>>>>>>        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="vDataSource1">
>>>>>>            <Columns>
>>>>>>                <asp:BoundField DataField="exp_1" HeaderText="exp_1" SortExpression="exp_1" />
>>>>>>                <asp:BoundField DataField="exp_2" HeaderText="exp_2" SortExpression="exp_2" />
>>>>>>            </Columns>
>>>>>>        </asp:GridView>
>>>>>>        <asp:SqlDataSource ID="vDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:vConnectionString %>"
>>>>>>            ProviderName="<%$ ConnectionStrings:vConnectionString.ProviderName %>"
>>>>>>SelectCommand="SELECT [title], [type_dish] FROM [dish] where recno()<22">
>>>>>>        </asp:SqlDataSource>
>>>>>>
>>>>>>    </div>
>>>>>>    </form>
>>>>>>
>>>>>>
>>>>>>>Would you show part of your code,especially SelectCommand.
>>>>>>>Cetin
>>>>>>>
>>>>>>>>Well, I sort of have it working now. When the web site loads, the dropdowns and gridview show exp_1,exp_2 for field headers and the grids display the field names as if it were data. Strange.
>>>>>>>>
>>>>>>>>
"Build a man a fire, and he's warm for a day.
Set a man on fire, and he's warm for the rest of his life."
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform