Sql Serverce

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Jan 2008
Posts: 24
Reputation: suganzeni is an unknown quantity at this point 
Solved Threads: 0
suganzeni suganzeni is offline Offline
Newbie Poster

Sql Serverce

 
0
  #1
Mar 3rd, 2008
Hi to all
I am working with Sql server ce for mobile application with vb.net.
I want to crete a table before that i have to check weather the table exists or not.
Also want to know about Object id in sql server and how to create it.
Thanks and Regards
Sugan
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,879
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 301
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Cenosillicaphobiac

Re: Sql Serverce

 
0
  #2
Mar 3rd, 2008
You could do that with sql:
  1. CREATE TABLE IF NOT EXISTS foo (bar int)
This creates a table foo, only if it hasn't been created before.

Niek
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 24
Reputation: suganzeni is an unknown quantity at this point 
Solved Threads: 0
suganzeni suganzeni is offline Offline
Newbie Poster

Re: Sql Serverce

 
0
  #3
Mar 3rd, 2008
Hi niek
Thanks for your help.
Following is the code i used.
But when i run the appliation it showing the follwoing error

There was an error parsing the query.[Token line number,Token line offset, Token in error,,]




Dim cn1 As SqlCeConnection = Nothing
cn1 = New SqlCeConnection("Data Source=\My Documents\myinsurance.sdf; " + "Password=")
Try
If cn1.State = ConnectionState.Open Then
cn1.Close()
End If
cn1.Open()

Dim sqlCreateTable As SqlCeCommand = cn1.CreateCommand()
sqlCreateTable.CommandText = "CREATE TABLE IF NOT EXISTS worklist(wcode ntext, wid int, description ntext, startdate datetime, enddate datetime, starttime ntext, endtime ntext,status ntext)"
sqlCreateTable.ExecuteNonQuery()


cn1.Close()
Catch sce As SqlCeException
MessageBox.Show(sce.Message)
End Try


sugan
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,879
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 301
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Cenosillicaphobiac

Re: Sql Serverce

 
0
  #4
Mar 4th, 2008
replace the 'ntext' with 'text' in your SQL-query.
and I think you meant 'starttime datetime' instead of 'starttime ntext'

Niek
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 24
Reputation: suganzeni is an unknown quantity at this point 
Solved Threads: 0
suganzeni suganzeni is offline Offline
Newbie Poster

Re: Sql Serverce

 
0
  #5
Mar 4th, 2008
Hi Niek
I am working with SQL SERVER CE.
I found the data types supported for SQL SERVER CE in the following link
http://msdn2.microsoft.com/en-us/lib...5(SQL.80).aspx
But there is no text data type only ntext avilable.

No time stamp also available
so i used datetime datatype for date and for time i used ntext and i type casted it to time in VB.NET application.

If i am running the following code
sqlCreateTable.CommandText = "CREATE TABLE meeting(mid int,type ntext, name ntext, startdate datetime, starttime datetime, endtime datetime, address ntext,status ntext)"
sqlCreateTable.ExecuteNonQuery()

The table is creted and i can also insert values to it.
But before creating this i want to check weather it exists or not.
Thanks
Last edited by suganzeni; Mar 4th, 2008 at 5:17 am.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,879
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 301
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Cenosillicaphobiac

Re: Sql Serverce

 
0
  #6
Mar 4th, 2008
aha.. I haven't worked with SQL on CE (yet).
So the following command doesn't work?
  1. CREATE TABLE IF NOT EXISTS meeting(mid int,type ntext, name ntext, startdate datetime, starttime datetime, endtime datetime, address ntext,status ntext)

Another (but ugly) option would be to try a SELECT query on the table (SELECT *) and if you get a MySQL-error, the table doesn't exist. But this is not fail-proof...

Niek

[edit] link
Last edited by niek_e; Mar 4th, 2008 at 5:30 am.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 24
Reputation: suganzeni is an unknown quantity at this point 
Solved Threads: 0
suganzeni suganzeni is offline Offline
Newbie Poster

Re: Sql Serverce

 
0
  #7
Mar 4th, 2008
Yes Nike
CREATE TABLE IF NOT EXISTS meeting(mid int,type ntext, name ntext, startdate datetime, starttime datetime, endtime datetime, address ntext,status ntext)
This is not working.
Also i tried with SELECT * command but it does not give me a good solution

Thanks
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 31
Reputation: AaronASterling is an unknown quantity at this point 
Solved Threads: 5
AaronASterling's Avatar
AaronASterling AaronASterling is offline Offline
Light Poster

Re: Sql Serverce

 
0
  #8
Mar 5th, 2008
Originally Posted by suganzeni View Post
Hi to all
I am working with Sql server ce for mobile application with vb.net.
I want to crete a table before that i have to check weather the table exists or not.
Also want to know about Object id in sql server and how to create it.
Thanks and Regards
Sugan
I am not so familiar with ce but i would say try

  1. IF OBJECT_ID(tablename) IS NULL
  2. CREATE table
  3. (
  4. ...
  5. )


if by object id you mean the OBJECT_ID system function then it is just a system function that returns the system ID of any object

Hope that helps,
Aaron
Aaron Sterling
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 2
Reputation: vinu_32123 is an unknown quantity at this point 
Solved Threads: 0
vinu_32123 vinu_32123 is offline Offline
Newbie Poster

Re: Sql Serverce

 
0
  #9
Oct 15th, 2008
i used following code it worked for me


string query1 = "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'RelationDocs' AND TABLE_TYPE = 'TABLE'";
sql.Connection = myConnection;
sql.CommandText = query1;
SqlCeDataReader reader = sql.ExecuteReader();
if (reader.Read() == false)
{

string query = "CREATE TABLE RelationDocs (Relation NVARCHAR(100) , Path NVARCHAR(100))";
cmd.Connection = myConnection;
cmd.CommandText = query;
cmd.ExecuteNonQuery();
}
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC