字符OleDB命令行的位置....? [英] position of a character OleDB command line .... ?

查看:78
本文介绍了字符OleDB命令行的位置....?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如何使用OleDB命令行获取角色的位置...



这里是我的代码


How to get the position of a character using OleDB Command line ...

here is my code below

dim pos1 as interger
dim line as string = textbox1.text

using cmd as new oledb.oledbcommand ("SELECT * from Table1 WHERE Instr('" & Textbox1.text & "', [column1] ",connstring)

cmd.parameters. addwithvalue("",Line)

if cInt(cmd.executescalar()) <> 0 then 
something ....  
else 
something...
end if 





所以这就是我不知道如何在命令中使用pos1变量来获取角色的位置....



thnxxa提前



任何帮助都应该受到赞赏....



So this was the case i dont know how to use pos1 variable in the command to get the position of a character ....

thnxxa in advance

any help should be appreciated....

推荐答案

哇 - 那个代码非常破碎:S



我首先要至少纠正语法:

Wow - That code is very broken :S

I'll start by at least correcting the syntax:
dim pos1 as interger
dim line as string = textbox1.text 


''Only ever use parameters (but it looks like your just trying to debug and this isn't your final code)
using cmd as new oledb.oledbcommand ("SELECT * from Table1 WHERE Instr(?, [column1] )",connstring) ''Don't forget closing brackets in the query
 
''Good practice to name every param in case you choose to add later
cmd.parameters. addwithvalue("@line",Line)
 
''The above query does not look like a scalar select.  Be careful
if cInt(cmd.executescalar()) <> 0 then 
something ....  
else 
something...
end if 







最简单的方法是使用IndexOf重新测试你得到的字符串



如果您真的想在查询中查看

CHARINDEX('bar','foobar')== 4

PATINDEX('%bar%','foobar')== 4



但是如果你想要索引和'*'那么它就不会是标量查询



希望有所帮助^ _ ^

Andy



更新:经验不足的详细解释:



标量查询是返回1行1列的查询。如果返回的是更多的那一行或一列,那么标量只会读取第一行和第一列。



如果这是你需要的,那么<$中的任何字符串c $ c> Textbox1 应该产生一个唯一的字符串,或者你应该以某种方式订购你的数据。我只能从你的代码中推断出这个。



变量赋值总是左边是变量,右边是值。所有编程语言都是如此。



我必须对你要做的事做出以下假设:

1:每个查询返回一个唯一的行,或者您不关心找到哪一行

2:您只需要查询中的1个值,即字符串的第一个索引



所以这里是:




The easiest way is to retest the string you get back with IndexOf

If you really want it in your query then look at
CHARINDEX('bar', 'foobar') == 4
PATINDEX('%bar%', 'foobar') == 4

But if you want the index and the '*' then it will not be a scalar query

Hope that helps ^_^
Andy

UPDATE: Details explanation for the less experienced:

A Scalar query is one that returns 1 row, 1 column. If more that one row or column is returned then a Scalar will only read the first row and first column.

If this is what you need then any string in Textbox1 should result in a unique string, or you should order your data is some way. I can only infer this from your code.

Variable assignments always have the variable on the left, and the value on the right. This is true of all programming languages.

I must make the following assumption about what you are trying to do:
1: Either each query returns a unique row or you don't care which row is found
2: You only want 1 value from the query, the first index of the string

So here it is:

dim pos1 as interger ''We will assign the result to this
dim line as string = textbox1.Text 


''Only ever use parameters. SQL Injection is a real danger!
using cmd as new oledb.oledbcommand ("SELECT CHARINDEX(?,[column1]) from Table1 WHERE Instr(?, [column1] )",connstring) ''Don't forget closing brackets in the query
 
''Good practice to name every param in case you choose to add later
cmd.parameters. addwithvalue("@line",line)
cmd.parameters. addwithvalue("@line2",line)
''This is why we name params.  Because you are using oledbm and we use the parameter twice, we must add it as two unique params
 
cmd.Connection.Open()
pos1 = cmd.executescalar()
cmd.Connection.Close()

if cInt(pos1) IS NOT NULL then ''Will be -1 if not found or null if no rows returned.  It cannot be -1 because there is the InStr() to make sure that it does exist
something ....  
else 
something...
end if 







尚未经过测试。您需要确保语法正确




This has not been tested. You will need to make sure that the syntax is correct


这篇关于字符OleDB命令行的位置....?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆