Monday, March 12, 2012

MySQL to MsSQL 2005

Hi!

How can i convert this code to work with MsSQL 2005?

/Tomas

PartialClass skaalbInherits System.Web.UI.PageProtected Sub Button1_Click(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles Button1.ClickDim strConnectionStringAs String Dim strQueryAs String Dim MyConnectionAs OdbcConnectionDim myCommandAs OdbcCommandDim pathAs String = Server.MapPath("~/album") &"/"Dim albNameAs String = Trim(Replace(txtAlbum.Text,"'", "''")) Dim folderName As String = Trim(Replace(txtAlbum.Text, "'", "''")) folderName = Replace(folderName," ","_")Try If Not My.Computer.FileSystem.DirectoryExists(path & folderName)Then My.Computer.FileSystem.CreateDirectory(path & folderName) labelStatus.Text ="Folder <b>" & folderName &"</b> created!"Dim BeskrivningAs String = Trim(Replace(txtBeskrivning.Text,"'", "''")) strConnectionString = "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=xxxxxxxx; DATABASE=xxxxxxx; UID=xxxxxxxx; PASSWORD=xxxxxxxxx; OPTION=3" MyConnection = New OdbcConnection(strConnectionString) MyConnection.Open() strQuery = "INSERT INTO tbl_albumet(alb_Namn, alb_Beskrivning, alb_Mapp) VALUES (?, ?, ?)" myCommand = New OdbcCommand(strQuery, MyConnection) myCommand.Parameters.AddWithValue("?", albName) myCommand.Parameters.AddWithValue("?", Beskrivning) myCommand.Parameters.AddWithValue("?", folderName) myCommand.ExecuteNonQuery() MyConnection.Close() Else labelStatus.Text = "Folder excist, pick another name!" End If Catch ex As Exception labelStatus.Text = "Unable to create folder!"End Try End SubEnd Class

Just useDriver={SQL Native Client}; in the connectionstring

No comments:

Post a Comment