Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Compact Framework / January 2006

Tip: Looking for answers? Try searching our database.

ADO.NET create table

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gandalf - 10 Jan 2006 11:07 GMT
Hi,

I'm trying to make index on a table with SQLCE, but I don't know how I can
do that in C#. For example, when I create a table in C# on PPC, I do the
following tasks :

---------------------------------------------------------------------------
cmndDB.CommandText =
" CREATE TABLE MOTIFS_ENL " +
"  ( CODE nchar(2) not null " +
"         CONSTRAINT PKMOTIFS_ENL PRIMARY KEY " +
"  , LIBELLE nchar(50) not null " +
"  )";
cmndDB.ExecuteNonQuery();
----------------------------------------------------------------------------

Thanks for any answer.
<ctacke/> - 10 Jan 2006 11:50 GMT
Look in SQL Books online under CREATE INDEX for the SQL syntax

-Chris

> Hi,
>
[quoted text clipped - 13 lines]
>
> Thanks for any answer.
Gandalf - 10 Jan 2006 12:40 GMT
OK, thanks.
But should I use the primary key as index, or should I add the index to the
current table ?

> Look in SQL Books online under CREATE INDEX for the SQL syntax
>
[quoted text clipped - 17 lines]
> >
> > Thanks for any answer.
Ginny Caughey [MVP] - 10 Jan 2006 13:12 GMT
Gandalf,

How large will the table be? Will you be using the primary key in your WHERE
clauses? Generally you would already know what kind of indexes your need.

If you are working with a SQL Mobile database, you can use SQL Server 2005
Management Studio to see the query plan generated by the query processor for
various queries to help determine if an index would help.

Signature

Ginny Caughey
.NET Compact Framework MVP

> OK, thanks.
> But should I use the primary key as index, or should I add the index to
[quoted text clipped - 24 lines]
>> >
>> > Thanks for any answer.
Gandalf - 17 Jan 2006 09:38 GMT
Thanks for your information.
In fact, the processus is the following : each time I scan a barcode, I
verify that the code isn't present in the table.

The loop in C# is the following :
------------------------------------------------
request = "SELECT CAB_COLIS FROM COLIS WHERE CAB_COLIS='"+code+"'";
if(clsD.searchData(request) == false)
{
// Display the code in a textbox and add the barcode in the table
}
else
{// Display an error message
}
-----------------------------------------------------

Where the searchData function is the following :
---------------------------------------------------------
public bool searchData(string req)
{
bool status = false;
SqlCeConnection connDB = new SqlCeConnection(strConn);       
SqlCeCommand cmndDB = new SqlCeCommand(req, connDB);
SqlCeDataReader drdrDB;               

try
{
connDB.Open();
drdrDB = cmndDB.ExecuteReader();           

while ( drdrDB.Read() )
{
status = true;               
}
               
drdrDB.Close();

connDB.Close();
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString(),
"Erreur",                System.Windows.Forms.MessageBoxButtons.OK,System.Windows.Forms.MessageBoxIcon.Hand,System.Windows.Forms.MessageBoxDefaultButton.Button2);
}
return status;
}
---------------------------------------------------------------------------

So, I open each time the connection to the database and I make a request
including the primary key in the where clause.

Thanks for any suggestion.

> Gandalf,
>
[quoted text clipped - 33 lines]
> >> >
> >> > Thanks for any answer.
Ginny Caughey [MVP] - 17 Jan 2006 17:55 GMT
Gandalf,

Then an index over CAB_COLIS would probably be a good idea unless the table
is quite small.

Signature

Ginny Caughey
.NET Compact Framework MVP

> Thanks for your information.
> In fact, the processus is the following : each time I scan a barcode, I
[quoted text clipped - 91 lines]
>> >> >
>> >> > Thanks for any answer.
Gandalf - 18 Jan 2006 17:30 GMT
OK, I tried to create an index :
--------------------------------------------------
CREATE INDEX ON MYTABLE (MY_COLUMN)
--------------------------------------------------

But I had always an index because if I looked on the Query Analyser on the
Pocket PC, I see under"MYTABLE" indexes "PKMYTABLE".
The PKMYTABLE is created by the following request : "CONSTRAINT PKMYTABLE
PRIMARY KEY".

So should I think that a PRIMARY KEY is equivalent as an INDEX ?

Thanks for any information.

> Gandalf,
>
[quoted text clipped - 96 lines]
> >> >> >
> >> >> > Thanks for any answer.
Ginny Caughey [MVP] - 18 Jan 2006 18:44 GMT
Gandalf,

If the key you're seeking on in the WHERE clause is your primary key, then
you don't need an additional index.

Signature

Ginny Caughey
.NET Compact Framework MVP

> OK, I tried to create an index :
> --------------------------------------------------
[quoted text clipped - 117 lines]
>> >> >> >
>> >> >> > Thanks for any answer.
Gandalf - 20 Jan 2006 13:38 GMT
OK, in fact I tried to make the following task and it seems to resolve the
problem :
when I insert data in the database, I made before an "open" and a "close"
connection to the database.
Now, during the insertion process, I make an open and then a close when the
data are inserted in the database.

Thanks for your information and your help.

> Gandalf,
>
[quoted text clipped - 122 lines]
> >> >> >> >
> >> >> >> > Thanks for any answer.
Chris Tacke, MVP - 18 Jan 2006 19:15 GMT
Just like I said on the 10th in this same thread, a primary key IS an index
and a clustered one at that.

-Chris

> OK, I tried to create an index :
> --------------------------------------------------
[quoted text clipped - 117 lines]
>> >> >> >
>> >> >> > Thanks for any answer.
<ctacke/> - 11 Jan 2006 01:34 GMT
A PK _is_ a clustered index.  As to whether you should add other indexes,
that all depends on your usage - only you (and the SQL Query Performance
Analyzer) can answer that.  As a general rule, if it's in a WHERE clause of
a statement used even semi-frequently, and index on the field will improve
query performance.

-Chris

> OK, thanks.
> But should I use the primary key as index, or should I add the index to
[quoted text clipped - 24 lines]
>> >
>> > Thanks for any answer.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.