Question Dynamically creating database

davco1

New member
Joined
Aug 10, 2005
Messages
4
Programming Experience
Beginner
I am using vb .net 2003 and sql 2000,and I am trying to create a database using textboxes to name them and I keep getting syntax errors with this code.


Dim cmd As New SqlCommand(strSQL, cn)
Dim res As String
res = TB1.Text

Dim strSQL As String = _
"IF EXISTS (" & _
"SELECT * " & _
"FROM master..sysdatabases " & _
"WHERE Name = )" + res & vbCrLf & _
"DROP DATABASE " + res & vbCrLf & _
"CREATE DATABASE " + res
cn.Open()
cmd.ExecuteNonQuery()
cn.Close()
Can anyone help me out with this problem?
Thanks in advance,
Marty
 
Presuming "Hack" is in TB1.Text, this is what your query looks like when you send it back to your database
VB.NET:
IF EXISTS (SELECT * FROM master..sysdatabases WHERE Name = )Hack
DROP DATABASE Hack
CREATE DATABASE Hack
See any problems here? ;)
 
Back
Top