create index Query throug ado.net

  • Thread starter Thread starter Dil
  • Start date Start date
D

Dil

hi all

Here am using "Use Database" keyword, as the connection string will
contain a different Initial Catalog

Pls let me know is there any Technical issues to execute this query
(Its working fine-)



Public Function GenerateCreateIndexQuery(ByVal TableName As String, _
ByVal IndexName As String, ByVal ColName As
String, _
ByVal dataBaseName As String)

Dim sqlStr As String

sqlStr = "USE " & dataBaseName & " IF EXISTS (SELECT name FROM
sysindexes WHERE name = '" & IndexName & "')"
sqlStr = sqlStr & " DROP INDEX " & TableName & "." & IndexName
sqlStr = sqlStr & " USE " & dataBaseName & " CREATE INDEX " &
IndexName & " ON "
sqlStr = sqlStr & TableName & "(" & ColName & ")"
Return sqlStr

End Function
 
Hi All,

Is it the right place where I will get the answer regarding this issue
if No
Plssssss let me know ..!!

Thanks in Advance
Dil
 
Dil,

There are better newsgroups by instance

Microsoft.public.dotnet.framework.adonet.

However at least for me is not clear what you mean with technical issues, so
don't expect any serious answer than things as "you should use parameters".

It is very much important where you use it, on what database server you use
it, what is the impact on security on your server, etc.

To give an analogy the question is the same as a question placed in a car
magazine.

I have now a Ford as car, it is fine for me, is there any Technical issue to
drive it.

Cor
 
Thanks Cor ur reply

Actually am trying to execute a SQL SERVER query

for example

sqlStr=" USE pubs
IF EXISTS (SELECT name FROM sysindexes
WHERE name = 'au_id_ind')
DROP INDEX authors.au_id_ind
GO
USE pubs
CREATE INDEX au_id_ind
ON authors (au_id)"

cmd.ExecuteNonquery(sqlStr)

Its working fine :)

I want to know this method is proper or not (Is there is any
disadvantages)

Thanks once again

Dil
 
Back
Top