HOW TO CREATE AN SQL DATABASE AND TABLE PROGRAMMATIC FROM VB.NET CODES

  • Thread starter Thread starter Clemence Mligo
  • Start date Start date
C

Clemence Mligo

Guest
Hi friends!

I'm here just to ask how can i create A database and then create a table to that database and insert some data just from codes without going to Microsoft Sql server???

One time i tried i tried creating a table via code but i got the following errow thrown:

'There is already an object named (' ') in the database.'

Does anyone know how to prevent this error from being thrown out from SQL server? how to catch that using try catch statement .

Also i know some errors are thrown from SQL Server itself , how to catch them and pass them to a window form control like a Message Box?

Some code i tried to create a Table inside an existing database is this below WHICH produced or throws an error i showed above everytime i do insert some record.i couldn't know how to prevent that error


Private Sub btnsaveextension_Click(sender As System.Object, e As System.EventArgs) Handles btnsaveextension.Click

Try
stringQuery= "if not exists (select * from sysobjects where name='Contract_TimeExtension' and xtype='U') USE MyFirstDB " & _
"CREATE TABLE [Contract_TimeExtension] ([Extension No] Integer NOT NULL,[Extension Approaved Date] Date NOT NULL," & _
"[Contractor Received Date] Date NOT NULL,[Extension Notes] Nvarchar(150) NOT NULL,[New Extended Date] Date NOT NULL, " & _
"[Contract ID]nvarchar(150) NOT NULL,[Contract Name] nvarchar(max) NOT NULL);")
Catch ex as Exception
MsgBox(ex.Message)

End Try
End Sub

Continue reading...
 
Back
Top