Click here to Skip to main content
16,006,348 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRepost Pin
Luc Pattyn13-May-10 8:38
sitebuilderLuc Pattyn13-May-10 8:38 
GeneralRe: Repost Pin
luccingolo14-May-10 5:16
luccingolo14-May-10 5:16 
GeneralRe: Repost Pin
Luc Pattyn14-May-10 5:43
sitebuilderLuc Pattyn14-May-10 5:43 
GeneralRe: Repost Pin
luccingolo14-May-10 6:21
luccingolo14-May-10 6:21 
AnswerRe: CREATE DATABASE parameter for FROM master..sysdatabases Pin
Dave Kreskowiak13-May-10 8:44
mveDave Kreskowiak13-May-10 8:44 
GeneralRe: CREATE DATABASE parameter for FROM master..sysdatabases Pin
luccingolo14-May-10 6:09
luccingolo14-May-10 6:09 
GeneralRe: CREATE DATABASE parameter for FROM master..sysdatabases Pin
Dave Kreskowiak14-May-10 7:48
mveDave Kreskowiak14-May-10 7:48 
GeneralRe: CREATE DATABASE parameter for FROM master..sysdatabases Pin
luccingolo14-May-10 21:26
luccingolo14-May-10 21:26 
Hi Dave,
i'm sorry but either you badly misunderstood my question or my english es even worse than i thought.
I AM USING SQL 2008 EXPRESS EDITION, nevertheless the code is not working.
The best i could get until now is an execution without an error. But in the end, i can't find any "new" (created) .mdf-file on my harddisk??? Confused | :confused:
Here comes the code.
Imports System.Data.SqlClient
Public Class Form1
    Private MyConnection As String

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        MyConnection = "Integrated Security=SSPI;" + "Initial Catalog=;" + "Data Source=.\SQLEXPRESS;" 'mydb

        Dim mySQL As String = "IF EXISTS (SELECT * FROM sys.databases WHERE name = 'MyDatabase')" & _
            "DROP DATABASE [MyDatabase];CREATE DATABASE [MyDatabase]"

        Try
            Dim conn As New SqlConnection(MyConnection)
            Dim myCmd As New SqlCommand(mySQL, conn)

            ' Open the connection, execute the command, and close the connection. It is more efficient to 
            '  ExecuteNonQuery when data is not being returned.

            If conn.State <> ConnectionState.Open Then conn.Open()

            myCmd.ExecuteNonQuery()
            conn.Close()

            ' Data has been successfully submitted

            MessageBox.Show("New Database has been ' successfully created !", _
                            " Database Creation Completed", MessageBoxButtons.OK, _
                            MessageBoxIcon.Information)
        Catch sqlExc As SqlException
            MessageBox.Show(sqlExc.ToString, "SQL Exception Error!", _
            MessageBoxButtons.OK, MessageBoxIcon.Error)

        Catch exc As Exception
            'If mstrConn = MyConnection Then
            '    ' Couldn't connect to SQL Server.  Now try MSDE.
            '    mstrConn = MY_MSDE_CONNECTION_STRING
            '    'Connecting to MSDE
            'Else
            '    ' Unable to connect to SQL Server or MSDE
            '    MessageBox.Show("SQL Or MSDE Connection Failed", _
            '         "Connection Failed!", MessageBoxButtons.OK, MessageBoxIcon.Error)
            '    End
            'End If
        End Try
    End Sub
End Class

Any idea of what's wrong here.
Thank you in anticipation,
Lucchingolo
QuestionHow to add a new contect menu in CD drive's popup menu? Pin
phowarso13-May-10 3:41
phowarso13-May-10 3:41 
QuestionHow to add a new popup menu in CD drive's popup menu? Pin
phowarso13-May-10 3:00
phowarso13-May-10 3:00 
AnswerRe: How to add a new popup menu in CD drive's popup menu? Pin
DaveAuld13-May-10 5:07
professionalDaveAuld13-May-10 5:07 
QuestionSave Excel Pin
MsmVc12-May-10 23:18
MsmVc12-May-10 23:18 
AnswerRe: Save Excel Pin
EliottA13-May-10 4:25
EliottA13-May-10 4:25 
AnswerRe: Save Excel Pin
The Man from U.N.C.L.E.13-May-10 6:48
The Man from U.N.C.L.E.13-May-10 6:48 
JokeRe: Save Excel Pin
Trevortni13-May-10 8:46
Trevortni13-May-10 8:46 
JokeRe: Save Excel Pin
Johnny J.13-May-10 21:54
professionalJohnny J.13-May-10 21:54 
Questionhow to insert jpegs into powerpoint via vb.net Pin
b-rad31112-May-10 5:39
b-rad31112-May-10 5:39 
AnswerRe: how to insert jpegs into powerpoint via vb.net Pin
Kschuler12-May-10 10:25
Kschuler12-May-10 10:25 
GeneralRe: how to insert jpegs into powerpoint via vb.net Pin
b-rad31112-May-10 10:27
b-rad31112-May-10 10:27 
Questionhow to save clipboard image as picture using vb.net Pin
b-rad31112-May-10 5:17
b-rad31112-May-10 5:17 
AnswerRe: how to save clipboard image as picture using vb.net Pin
Luc Pattyn12-May-10 5:32
sitebuilderLuc Pattyn12-May-10 5:32 
GeneralRe: how to save clipboard image as picture using vb.net Pin
b-rad31112-May-10 5:34
b-rad31112-May-10 5:34 
GeneralRe: how to save clipboard image as picture using vb.net Pin
Luc Pattyn12-May-10 5:39
sitebuilderLuc Pattyn12-May-10 5:39 
GeneralRe: how to save clipboard image as picture using vb.net Pin
b-rad31112-May-10 5:41
b-rad31112-May-10 5:41 
QuestionWise InstallMaster to create setup file Pin
Andraw Tang12-May-10 5:03
Andraw Tang12-May-10 5:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.