3 Replies - 1044 Views - Last Post: 21 July 2009 - 08:56 AM Rate Topic: -----

#1 whitekeeper  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 17-July 09

Creating New Table in a Database. Help me T_T

Posted 17 July 2009 - 11:30 PM

Below is my code for creating a database and then, from there i hope to be able to create more than one tables in the same database that i just created. But for some reason, Visual studio 2005 keeps reminding me that the SqlCeException was not handled or mishandled. Error lies in the "sqlCreateTable.ExecuteNonQuery()" Please help me. Thank. I admit i'm new to this so its alright to call me noob for this. All help is appreciated.

______________________________________________________________________


Private Sub Salesman_Login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

		If System.IO.File.Exists("\My Documents\Salesman.sdf") Then
			System.IO.File.Delete("\My Documents\Salesman.sdf")
		End If

		Dim engine As New SqlCeEngine("Data Source = \My Documents\Salesman.sdf")
		engine.CreateDatabase()

		Dim sqlCreateTable As SqlCeCommand = ssceconn.CreateCommand()

		sqlCreateTable.CommandText = _
		"CREATE TABLE Login(user_id int IDENTITY(0,1) PRIMARY KEY, f_name ntext, l_name ntext, user_name nvarchar(10), password nvarchar(10), email ntext)" & vbCrLf & _
		"CREATE TABLE Order(product_id int IDENTITY(0,1) PRIMARY KEY, retailer_name nvarchar(20), product_name nvarchar(20), quantity ntext)"

		ssceconn.Open()
		sqlCreateTable.ExecuteNonQuery()
		ssceconn.Close()


	End Sub



_____________________________________________________________________


Actually i heard from someone that you can actually create all the tables that you need such as "Login", "Order" and so on in a single windows form(in form_load) , which will load up all your table and create them for you if that window form is the first object to start running in the order.

This post has been edited by whitekeeper: 18 July 2009 - 12:21 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Creating New Table in a Database. Help me T_T

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9097
  • View blog
  • Posts: 34,181
  • Joined: 12-June 08

Re: Creating New Table in a Database. Help me T_T

Posted 18 July 2009 - 08:51 AM

Have you tried breaking up the 'create table' commands into two separate 'execute not query'?
Was This Post Helpful? 0
  • +
  • -

#3 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1639
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Creating New Table in a Database. Help me T_T

Posted 18 July 2009 - 09:19 AM

modi123_1 has what should be the proper resolution. If I'm not mistaken you cannot execute multiple statements like that, it has to be two different executions.
Was This Post Helpful? 0
  • +
  • -

#4 whitekeeper  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 17-July 09

Re: Creating New Table in a Database. Help me T_T

Posted 21 July 2009 - 08:56 AM

Thanks dude, it works and also the word "order" cannot be use because it is a reserved word in the program. Haha. Silly me.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1