473,402 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Checking for table existence

Hi

How can I check for existence of a certain table by name in and access
database and if the table exists find the number of records in it?

I guess I can access this information by setting up a dataset for the
database but I am wondering if there is a quick way to find this.

Thanks

Regards
Jan 19 '08 #1
46 1805
Issuing a count select statement within a try catch loop would handle both?

It would give you the total records if the table exists and error and enter
the catch code if it doesn't?
Rob

"John" <Jo**@nospam.infovis.co.ukwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
Hi

How can I check for existence of a certain table by name in and access
database and if the table exists find the number of records in it?

I guess I can access this information by setting up a dataset for the
database but I am wondering if there is a quick way to find this.

Thanks

Regards

Jan 19 '08 #2
"Rob Blackmore" <ro*@robblackmore.comwrote in
news:66**********************************@microsof t.com:
Issuing a count select statement within a try catch loop would handle
both?

It would give you the total records if the table exists and error and
enter the catch code if it doesn't?
A better way would be to use ADO.NET's GetSchema or query the metadata
table directly to check if a table exists.
--
sp**********@rogers.com (Do not e-mail)
Jan 19 '08 #3
John wrote:
How can I check for existence of a certain table by name in and access
database and if the table exists find the number of records in it?
Rob Blackmore's approach will certainly work, but if you prefer to check for
the existence of the table without getting an exception if it doesn't exist
(which is definitely my preferred approach), here's a way that will work:

\\\
Dim tableInfo As DataTable
tableInfo = oleConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables , New
String() {Nothing, Nothing, "TableName", "TABLE"})
///

The GetOleDbSchemaTable method will return a datatable containing schema
information. This set of parameters will return information about a table
called "TableName" if one exists. Check the tableInfo.Rows.Count after
executing this; if it contains zero then the table doesn't exist, if it
contains one then it does exist.

Then if it exists, execute the SELECT COUNT statement as mentioned in Rob's
email.

HTH,

--

(O)enone
Jan 19 '08 #4
Hi John,

I never understand this kind of questions. You are making the program and
you don't know the name of the table which you (or a cowerker) would have
given a name.

How can this happen?

Cor

"John" <Jo**@nospam.infovis.co.ukschreef in bericht
news:%2****************@TK2MSFTNGP02.phx.gbl...
Hi

How can I check for existence of a certain table by name in and access
database and if the table exists find the number of records in it?

I guess I can access this information by setting up a dataset for the
database but I am wondering if there is a quick way to find this.

Thanks

Regards

Jan 20 '08 #5
Hi Cor

I know the name of the table but it may or may not exist and I need to check
for the existence of the table.

Regards
"Cor Ligthert[MVP]" <no************@planet.nlwrote in message
news:1C**********************************@microsof t.com...
Hi John,

I never understand this kind of questions. You are making the program and
you don't know the name of the table which you (or a cowerker) would have
given a name.

How can this happen?

Cor

"John" <Jo**@nospam.infovis.co.ukschreef in bericht
news:%2****************@TK2MSFTNGP02.phx.gbl...
>Hi

How can I check for existence of a certain table by name in and access
database and if the table exists find the number of records in it?

I guess I can access this information by setting up a dataset for the
database but I am wondering if there is a quick way to find this.

Thanks

Regards


Jan 20 '08 #6
Cor Ligthert[MVP] wrote:
I never understand this kind of questions. You are making the program
and you don't know the name of the table which you (or a cowerker)
would have given a name. How can this happen?
There are lots of systems that don't have fixed, known database structures.

The system I work on has dozens of different databases working for different
clients. We then offer a range of plug-ins to perform various tasks, each of
which will create tables for its own storage needs. The set of tables
therefore is not fixed, and it can be necessary for one part of the system
to check a table's presence because another part of the system may or may
not be present.

--

(O)enone
Jan 20 '08 #7
John,

Then I would just create a simple SQL command with

"Select * from MyTable"

Execute that with an executescalar and when I get an error then I know that
the table does not exist.

Cor

Jan 20 '08 #8
On Jan 20, 7:53*pm, "Cor Ligthert[MVP]" <notmyfirstn...@planet.nl>
wrote:
John,

Then I would just create a simple SQL command with

"Select * from MyTable"

Execute that with an executescalar and when I get an error then I know that
the table does not exist.

Cor
Cor's tip is the most basic and comprehensive one. When you call
something from a non-existed database, an error will occur and you
won't be able to access then you can use try-catch or kinda things to
display a custom error message.
Jan 20 '08 #9
No, that's an improper and silly way to check for a table existence.
What exception will you get? Will it be due to the lack of table existance
or due to some other error?
And don't forget that exceptions are for exceptional situations, not for
known situations: in your case, table might or might not exist. And if it
doesn't then this isn't an exception.
The proper way is to use GetSchema method - as (O)enone suggested and if
available or execute a DDL statement - almost each database will let you
query for a table using some sort of query statement.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/
"kimiraikkonen" <ki*************@gmail.comwrote in message
news:3a**********************************@e6g2000p rf.googlegroups.com...
On Jan 20, 7:53 pm, "Cor Ligthert[MVP]" <notmyfirstn...@planet.nl>
wrote:
John,

Then I would just create a simple SQL command with

"Select * from MyTable"

Execute that with an executescalar and when I get an error then I know
that
the table does not exist.

Cor
Cor's tip is the most basic and comprehensive one. When you call
something from a non-existed database, an error will occur and you
won't be able to access then you can use try-catch or kinda things to
display a custom error message.

Jan 20 '08 #10
On Jan 20, 8:37 pm, "Miha Markic" <miha at rthand comwrote:
No, that's an improper and silly way to check for a table existence.
What exception will you get? Will it be due to the lack of table existance
or due to some other error?
And don't forget that exceptions are for exceptional situations, not for
known situations: in your case, table might or might not exist. And if it
doesn't then this isn't an exception.
The proper way is to use GetSchema method - as (O)enone suggested and if
available or execute a DDL statement - almost each database will let you
query for a table using some sort of query statement.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & developmentwww.rthand.com
Blog:http://cs.rthand.com/blogs/blog_with_righthand/

"kimiraikkonen" <kimiraikkone...@gmail.comwrote in message

news:3a**********************************@e6g2000p rf.googlegroups.com...
On Jan 20, 7:53 pm, "Cor Ligthert[MVP]" <notmyfirstn...@planet.nl>
wrote:
John,
Then I would just create a simple SQL command with
"Select * from MyTable"
Execute that with an executescalar and when I get an error then I know
that
the table does not exist.
Cor

Cor's tip is the most basic and comprehensive one. When you call
something from a non-existed database, an error will occur and you
won't be able to access then you can use try-catch or kinda things to
display a custom error message.
Doesn't executescalar method return an exception if it fails to
retrieve data from a specific data table due to absence of it?
Jan 20 '08 #11
Miha,

There is no question what error you will get, there can only be one error on
this, the table does not exist.
(It can be as well a connection problem or a complete absence of the
database, however then you don"t get a schema either)

Cor

Jan 21 '08 #12
"Miha Markic" <miha at rthand comwrote in message
news:OL**************@TK2MSFTNGP04.phx.gbl...
And don't forget that exceptions are for exceptional situations, not for
known situations
This statement is false.

Jan 21 '08 #13
Care to explain?

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

"Guru" <ru*****@interference.nitwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
"Miha Markic" <miha at rthand comwrote in message
news:OL**************@TK2MSFTNGP04.phx.gbl...
>And don't forget that exceptions are for exceptional situations, not for
known situations

This statement is false.
Jan 21 '08 #14

"Cor Ligthert[MVP]" <no************@planet.nlwrote in message
news:60**********************************@microsof t.com...
Miha,

There is no question what error you will get, there can only be one error
on this, the table does not exist.
(It can be as well a connection problem or a complete absence of the
database, however then you don"t get a schema either)
Yes, but how do you tell if the table exists or not? Was it a connection
problem? Was there a timeout? Or is just table missing?
There is also a performance hit doing it that way.
If you do it properly, you get a true/false or an exception telling you that
query failed.
--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Jan 21 '08 #15
"Miha Markic" <miha at rthand comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
Care to explain?
See: news:Ox**************@TK2MSFTNGP05.phx.gbl

A not exceptional situation that is fully known and epected to occur in the
scenario given.

And also see: news:uv****************@TK2MSFTNGP05.phx.gbl

"...you are utterly oblivious to the concept of using Try/Catch as a
versatile, robust, and flexible programming tool that has grand purposes
well beyond merely trapping the woe-begotten side-effects of your miserably
inept coding style..."
news:u2**************@TK2MSFTNGP02.phx.gbl

Care to dispute?
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

"Guru" <ru*****@interference.nitwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>"Miha Markic" <miha at rthand comwrote in message
news:OL**************@TK2MSFTNGP04.phx.gbl...
>>And don't forget that exceptions are for exceptional situations, not for
known situations

This statement is false.

Jan 21 '08 #16
"Herfried K. Wagner [MVP]" <hi***************@gmx.atwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
"Miha Markic" <miha at rthand comschrieb:
>>>And don't forget that exceptions are for exceptional situations, not
for known situations

This statement is false.

Care to explain?

Guru seems to be a troll.
You are not completely wrong.
However, he is not completely wrong.
I am completely right.
Jan 21 '08 #17

"Guru" <ru*****@interference.nitwrote in message
news:eg*************@TK2MSFTNGP04.phx.gbl...
"Miha Markic" <miha at rthand comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
>Care to explain?

See: news:Ox**************@TK2MSFTNGP05.phx.gbl

A not exceptional situation that is fully known and epected to occur in
the scenario given.
You should simply test for the length of Item.SomeProperty beforehand - it
is way cheaper than using try/catch.
Note: this is a known situation you can deal with without exceptions.
The only situation when exceptions might come handy are recursions.
>
And also see: news:uv****************@TK2MSFTNGP05.phx.gbl
Can't find this one.
>
"...you are utterly oblivious to the concept of using Try/Catch as a
versatile, robust, and flexible programming tool that has grand purposes
well beyond merely trapping the woe-begotten side-effects of your
miserably inept coding style..."
news:u2**************@TK2MSFTNGP02.phx.gbl
Care to dispute?
Why should I dispute you? Seems that you've figured out everything.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Jan 21 '08 #18
Guru,

You are very offensive due to your ignorance.
Look at the referenced message and you'll see that try/catch block is
*inside* the loop. Now, redo your tests with try/catch block inside the loop
and you'll see the performance difference.
nLen = PerformSomeReallyWeirdCalculation(Item.SomePropert y)
How do you predict the value of nLen from the value of
Item.SomeProperty.Length?

You don't have to predict it. You check how long the Item.SomeProperty
string is and avoid throwing an exception if the nLen is higher. Is it as
simple as that.

Now, please, calm down and take a big breath before you start calling people
stupid, ignorant or idiots.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Jan 21 '08 #19
"Miha Markic" <miha at rthand comwrote in message
news:OQ**************@TK2MSFTNGP06.phx.gbl...
Guru,

You are very offensive due to your ignorance.
Look at the referenced message and you'll see that try/catch block is
*inside* the loop. Now, redo your tests with try/catch block inside the
loop and you'll see the performance difference.
See end of this message...
>nLen = PerformSomeReallyWeirdCalculation(Item.SomePropert y)

How do you predict the value of nLen from the value of
Item.SomeProperty.Length?

You don't have to predict it. You check how long the Item.SomeProperty
string is and avoid throwing an exception if the nLen is higher. Is it as
simple as that.
Not so. Go back to the referenced message and read it, but first, learn to
read.
Now, please, calm down and take a big breath before you start calling
people stupid, ignorant or idiots.
...said the stupid, ignorant idiot.

Dim sw As New Stopwatch
Dim nCount As Integer

sw.Start()
For nZ As Integer = 1 To 2000000
If nZ = -1 Then
Exit For
Else
nCount += 1
End If
Next
sw.Stop()

Console.WriteLine(sw.ElapsedMilliseconds)

sw.Reset()
sw.Start()
Try
For nz As Integer = 1 To 2000000
nCount += 1
Next
Catch ex As Exception
Stop
End Try
sw.Stop()

Console.WriteLine(sw.ElapsedMilliseconds)

sw.Reset()
sw.Start()
For nz As Integer = 1 To 2000000
nCount += 1
Next
sw.Stop()
Console.WriteLine(sw.ElapsedMilliseconds)

sw.Reset()
sw.Start()
For nz As Integer = 1 To 2000000
Try
nCount += 1
Catch ex As Exception
Stop
End Try
Next
sw.Stop()
Console.WriteLine(sw.ElapsedMilliseconds)

12
8
8
7

BWAHAHAHAHAHAHAHAHAHAHA!

You were saying, mister genius MVP?
Jan 21 '08 #20
You need to increase the number of iterations to get anything meaningful,
and also need to ensure you aren't seeing a JIT optimization due to the
block placement. The later can be usually solved by either calling separate
methods , or by repeating the same blocks in code. When you do this, you
will see the cost is about the same when the exception condition is not
triggered. However, if testing for the exception condition you will find
that the exception is more expensive.
"Guru" <ru*****@interference.nitwrote in message
news:O9**************@TK2MSFTNGP05.phx.gbl...
"Miha Markic" <miha at rthand comwrote in message
news:OQ**************@TK2MSFTNGP06.phx.gbl...
>Guru,

You are very offensive due to your ignorance.
Look at the referenced message and you'll see that try/catch block is
*inside* the loop. Now, redo your tests with try/catch block inside the
loop and you'll see the performance difference.

See end of this message...
>>nLen = PerformSomeReallyWeirdCalculation(Item.SomePropert y)

How do you predict the value of nLen from the value of
Item.SomeProperty.Length?

You don't have to predict it. You check how long the Item.SomeProperty
string is and avoid throwing an exception if the nLen is higher. Is it as
simple as that.

Not so. Go back to the referenced message and read it, but first, learn to
read.
>Now, please, calm down and take a big breath before you start calling
people stupid, ignorant or idiots.

...said the stupid, ignorant idiot.

Dim sw As New Stopwatch
Dim nCount As Integer

sw.Start()
For nZ As Integer = 1 To 2000000
If nZ = -1 Then
Exit For
Else
nCount += 1
End If
Next
sw.Stop()

Console.WriteLine(sw.ElapsedMilliseconds)

sw.Reset()
sw.Start()
Try
For nz As Integer = 1 To 2000000
nCount += 1
Next
Catch ex As Exception
Stop
End Try
sw.Stop()

Console.WriteLine(sw.ElapsedMilliseconds)

sw.Reset()
sw.Start()
For nz As Integer = 1 To 2000000
nCount += 1
Next
sw.Stop()
Console.WriteLine(sw.ElapsedMilliseconds)

sw.Reset()
sw.Start()
For nz As Integer = 1 To 2000000
Try
nCount += 1
Catch ex As Exception
Stop
End Try
Next
sw.Stop()
Console.WriteLine(sw.ElapsedMilliseconds)

12
8
8
7

BWAHAHAHAHAHAHAHAHAHAHA!

You were saying, mister genius MVP?
Jan 21 '08 #21
sw.Reset()
sw.Start()
For nz As Integer = 1 To 2000000
nCount += 1
Next
sw.Stop()
Console.WriteLine(sw.ElapsedMilliseconds)

sw.Reset()
sw.Start()
For nz As Integer = 1 To 2000000
Try
nCount += 1
Catch ex As Exception
Stop
End Try
Next
sw.Stop()
Console.WriteLine(sw.ElapsedMilliseconds)

12
8
8
7

BWAHAHAHAHAHAHAHAHAHAHA!

You were saying, mister genius MVP?
Based on your results, a simple loop is slower than same loop with try/catch
block? Now, that's a representative result.
Looks like try/catch block actually increases the speed, perhaps reduces the
cpu cycles required for an operation.
I suggest you to follow your recipe: placer try/catch blocks in every loop
you have and your app will run faster.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Jan 21 '08 #22
"Bill McCarthy" <Bi**@NOSPAM.comwrote in message
news:Ot**************@TK2MSFTNGP03.phx.gbl...
>
"Guru" <ru*****@interference.nitwrote in message
news:eY**************@TK2MSFTNGP02.phx.gbl...
>>
You do it.

Well I suggest you take the time to look at what was said to you. The
test results you posted were ludicrous.
Then post your own.

HTH
Jan 21 '08 #23
No. I am saying you can test within a very good degree of likelihood
whether or not the command will execute properly based on past experience
and empirical data.

Can't you read or something?
I can, it looks like you can't. You are pinging OS and based on that ping
you know to a *very good degree of likelihood* (translate that into binary
world of computers, please) that command against *database server* will
execute. Is your ping telling you that database service is running and
database service is ready to execute you command? Furthermore your silly
ping doesn't even tell if connection to database server is still valid.
--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Jan 21 '08 #24
"Miha Markic" <miha at rthand comwrote in message
news:eA**************@TK2MSFTNGP02.phx.gbl...
>No. I am saying you can test within a very good degree of likelihood
whether or not the command will execute properly based on past experience
and empirical data.

Can't you read or something?

I can, it looks like you can't. You are pinging OS and based on that ping
you know to a *very good degree of likelihood* (translate that into binary
world of computers, please)
Sure... in a pinch. 8, 16 or 32-bit wide binary?

01010100 01101110 10100110 01001110 10011110 00000100 11100110 11110110
11110110 00100110 00000100 00100110 10100110 11100110 01001110 10100110
10100110 00000100 11110110 01100110 00000100 00110110 10010110 11010110
10100110 00110110 10010110 00010110 11110110 11110110 00100110 01010100
that command against *database server* will execute.
No, that is not what I claimed. Do you need me to quote the text and shove
it up your nostrils yet again?
Is your ping telling
you that database service is running and database service is ready to
execute you command?
How did you manage to get that silly question from what I wrote originally?
Furthermore your silly ping doesn't even tell if
connection to database server is still valid.
Even Blind Freddy knows that a ping won't tell you if the connection to a
database server is still valid, you utter moron.

Jan 21 '08 #25
>that command against *database server* will execute.
>
No, that is not what I claimed. Do you need me to quote the text and shove
it up your nostrils yet again?
>Is your ping telling
you that database service is running and database service is ready to
execute you command?

How did you manage to get that silly question from what I wrote
originally?
>Furthermore your silly ping doesn't even tell if
connection to database server is still valid.

Even Blind Freddy knows that a ping won't tell you if the connection to a
database server is still valid, you utter moron.

Please, reread what have you written before. How can one "test within a very
good degree of likelihood whether or not the command will
execute properly " without knowing the connection state?

1.
"Although you know that connection might drop, you can't know in advance.

This statement is false.
Dim WithEvents Pong as New Ping()
Pong.Send(IPAddress)
Private Sub Pong_PingCompleted(ByVal sender As Object, ByVal e As _
PingCompletedEventArgs) Handles Pong.PingCompleted

If e.Reply.Status <IPStatus.Success Then
GiveUP()
ElseIf e.Reply.RoundtripTime 750 Then
TryAgainLater()
End If
End Sub"

2.
"If so, then you
know just as well as I do that your previous claim that "you can't test
whether the command will execute properly..." is patently false; you can
test within a very good degree of likelihood whether or not the command will
execute properly based on past experience and empirical data."

3.
"No. I am saying you can test within a very good degree of likelihood
whether
or not the command will execute properly based on past experience and
empirical data."

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Jan 21 '08 #26
how about you just do:
select table_name from information_schema.tables where table_name =
'yourTableName'

this will return one row if the table exists and no rows if the table
doesn't exist.
no need for exception etc...

"(O)enone" wrote:
There are lots of systems that don't have fixed, known database structures.

The system I work on has dozens of different databases working for different
clients. We then offer a range of plug-ins to perform various tasks, each of
which will create tables for its own storage needs. The set of tables
therefore is not fixed, and it can be necessary for one part of the system
to check a table's presence because another part of the system may or may
not be present.

--

(O)enone
Jan 21 '08 #27
Excuse me, but with all due respect - are you kidding?
ML

---
Matija Lah, SQL Server MVP
http://milambda.blogspot.com/
Jan 21 '08 #28
"ML" <ML@discussions.microsoft.comwrote in message
news:FD**********************************@microsof t.com...
Excuse me
Did you fart?
Jan 21 '08 #29
If you throw a tennis ball at an outer wall of a house and it comes back, can
you say that any of the residents are in the house at that very moment?
ML

---
Matija Lah, SQL Server MVP
http://milambda.blogspot.com/
Jan 21 '08 #30
"Guru" <ru*****@interference.nitschrieb:
>Well I suggest you take the time to look at what was said to you. The
test results you posted were ludicrous.

Then post your own.
Your proof which should give substance to your claims is flawed (Bill
explained why). No need for anybody except /you/ to provide a serious
proof.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Jan 21 '08 #31
"ML" <ML@discussions.microsoft.comwrote in message
news:8B**********************************@microsof t.com...
If you throw a tennis ball at an outer wall of a house and it comes back,
can
you say that any of the residents are in the house at that very moment?
If a tree falls in a forest and nobody hears it, does it mak a sound?
Jan 21 '08 #32
Yeah, well, post back when you have the answer. Or when you've sobered up...
ML

---
Matija Lah, SQL Server MVP
http://milambda.blogspot.com/
Jan 21 '08 #33
"ML" <ML@discussions.microsoft.comwrote in message
news:51**********************************@microsof t.com...
Yeah, well, post back when you have the answer. Or when you've sobered
up...
You're not getting laid, are you?
Jan 21 '08 #34
"Herfried K. Wagner [MVP]" <hi***************@gmx.atwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
"Guru" <ru*****@interference.nitschrieb:
>>Well I suggest you take the time to look at what was said to you. The
test results you posted were ludicrous.

Then post your own.

Your proof which should give substance to your claims is flawed (Bill
explained why). No need for anybody except /you/ to provide a serious
proof.
LOL (Bill explained why) by writing a segment of code exactly has I had
written it, then snipped the proof when his idiocy was rammed into his
gormless face.
Jan 21 '08 #35
Cool down, dear, I'm at the office. :)
ML

---
Matija Lah, SQL Server MVP
http://milambda.blogspot.com/
Jan 21 '08 #36
"ML" <ML@discussions.microsoft.comwrote in message
news:24**********************************@microsof t.com...
Cool down, dear, I'm at the office. :)
Real meaning: No.
Jan 21 '08 #37
"ML" <ML@discussions.microsoft.comwrote in message
news:24**********************************@microsof t.com...
Cool down, dear, I'm at the office. :)
Real meaning: No.
Jan 21 '08 #38
:)
ML

---
Matija Lah, SQL Server MVP
http://milambda.blogspot.com/
Jan 21 '08 #39
"ML" <ML@discussions.microsoft.comwrote in message
news:24**********************************@microsof t.com...
Cool down, dear, I'm at the office. :)
Real meaning: No.
Jan 21 '08 #40
In article <#4**************@TK2MSFTNGP02.phx.gbl>, Miha Markic wrote:
Please, reread what have you written before. How can one "test within a very
good degree of likelihood whether or not the command will
execute properly " without knowing the connection state?

Not to defend a self-admitted troll, but...by having known common
failures.
If a particular condition always causes a failure, and that condition
is the cause of X% of failures, you can avoid making an attempt that is
doomed to failure by first testing the condition.

If X is the vast majority of failures, then your confidence in the
success of an attempt can reasonably be tied to whether or not the
condition exist.

So, empirical data can tell you where to put your effort.

(On the other hand, I think your basic point was that exceptions
shouldn't be used when there is a more straightforward way of returning
the same information is valid).

--
J.B. Moreno
Jan 22 '08 #41
So, empirical data can tell you where to put your effort.

Sure, empirical data helps - but that's it. But you still don't know whether
connection will hold or not as you can't predict future from past.
>
(On the other hand, I think your basic point was that exceptions
shouldn't be used when there is a more straightforward way of returning
the same information is valid).
Yep, that was my point.
--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Jan 22 '08 #42
So, empirical data can tell you where to put your effort.

And don't forget that doing ping is also a performance issue - you would
need two roundtrips to the server instead of one.
--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Jan 22 '08 #43
"Miha Markic" <miha at rthand comwrote in message
news:Ov**************@TK2MSFTNGP02.phx.gbl...
>So, empirical data can tell you where to put your effort.

And don't forget that doing ping is also a performance issue - you would
need two roundtrips to the server instead of one.
LMAO - you will write any old crap just to try and avoid losing face.
--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Jan 22 '08 #44
"Guru" wrote:
"ML" <ML@discussions.microsoft.comwrote in message
news:8B**********************************@microsof t.com...
If you throw a tennis ball at an outer wall of a house and it comes back,
can
you say that any of the residents are in the house at that very moment?

If a tree falls in a forest and nobody hears it, does it mak a sound?
If a man says something in a forest, is he still wrong? :-)

--
David Streeter
Synchrotech Software
Sydney Australia
Jan 23 '08 #45
I'm going to take mercy on you. I think this is what you are looking for:

private bool TableExists(string connString, string tableName)
{
SqlConnection cn = New SqlConnection(connString);
cn.Open();
DataTable dt = cn.GetSchema("Tables");
foreach (DataRow rw in dt.Rows)
{
if (rw("TABLE_NAME")).ToUpper() == tableName)
return true;
}
return false;
}

RobinS.
----------------------------
"John" <Jo**@nospam.infovis.co.ukwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
Hi

How can I check for existence of a certain table by name in and access
database and if the table exists find the number of records in it?

I guess I can access this information by setting up a dataset for the
database but I am wondering if there is a quick way to find this.

Thanks

Regards

Jan 24 '08 #46
Hi Robin

Many thanks, I'll use this one.

Thanks again.

Regards

"RobinS" <ro****@imnottelling.comwrote in message
news:f8******************************@comcast.com. ..
I'm going to take mercy on you. I think this is what you are looking for:

private bool TableExists(string connString, string tableName)
{
SqlConnection cn = New SqlConnection(connString);
cn.Open();
DataTable dt = cn.GetSchema("Tables");
foreach (DataRow rw in dt.Rows)
{
if (rw("TABLE_NAME")).ToUpper() == tableName)
return true;
}
return false;
}

RobinS.
----------------------------
"John" <Jo**@nospam.infovis.co.ukwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>Hi

How can I check for existence of a certain table by name in and access
database and if the table exists find the number of records in it?

I guess I can access this information by setting up a dataset for the
database but I am wondering if there is a quick way to find this.

Thanks

Regards


Jan 24 '08 #47

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: GujuBoy | last post by:
i want to check to see if a certain program is installed on my windows box using python. how can i do that...(ie, i want to see if "word" is installed) please help
1
by: Xeno Campanoli | last post by:
I'm having a hard time checking existence of windows. The only thing I found on this is page 224 of Rhino. Why is there no function to check this? Is there a publication on this part of the...
2
by: mike | last post by:
I had a form like below that validated that a file was there before it would submit. <form name="attach" method="POST" action="run_this_pgm.cfm" enctype="multipart/form-data"...
5
by: Richard L Rosenheim | last post by:
What's the proper technique for checking for the existence of an attribute within a node? Lets say I did a SelectSingleNode which returned this element: <AnAddress city="San Francisco"...
10
by: Ken | last post by:
how to check if a table is exist then drop it if true, false to ignore the SQL statement, for example, drop table person if exist;
1
by: Vikas Rana | last post by:
Hi, I am having trouble checking the existence of a temporary table. Neither of pg_tables or pg_class list the temporary tables. Is there any way to get the list of temporary tables? ...
2
by: DeanL | last post by:
Hi Everyone, Does anyone know a way to "check" if a record number is in existence when someone is adding a new record? Currently working on an awfully designed Access 97 database (that I'm not...
2
by: Robert Bravery | last post by:
HI all, I want check for the existence of a particular table in sql. Then branch code on the result I was thinking of a command something like: IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id...
4
by: Patient Guy | last post by:
Does anyone have any coding rules they follow when doing argument checking? When arguments fail during check, do you return from the call with an ambiguous return value, or do you throw...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.