How can I check the existence of database [duplicate] - c#

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How to check for the existence of a DB?
How can I check the existance of database and if it exist how can I delete it?

Check out this page:
http://akrabat.com/winphp-challenge/retriving-a-list-of-database-from-sql-server/
It tells you how to retrieve a list of databases on an sql-server. After that, I think a
DROP DATABASE ...
should do the trick.

Related

How may i use File.exists in Datatable.select expression [duplicate]

This question already has answers here:
Check if value exists in dataTable?
(5 answers)
Closed 6 years ago.
I have a datatable which contain a column Path of file. Now i want to filter file Path is exist or not.
DataTable.Select(File.Exists(ColumnsName))
Would you please help me how may i filter.
You can filter datatable by file path column by checking existence using File.Exists
var result = dataTable.AsEnumerable().Where(r=>File.Exists(r.Field<string>("Path"));
DataSets are a pretty old concept in .NET so to use LINQ you need a bit of extra syntax:
dataTable.Rows.Cast<DataRow>().Select(row => File.Exists(row.Field<String>(columnName)))
This will return an IEnumerable<Boolean> that determines if the files exist.

In File.Exists() how to know if the file is the reall file or a shortcut? [duplicate]

This question already has answers here:
Check if a file is real or a symbolic link
(9 answers)
How do i get the path name from a file shortcut ? Getting exception [duplicate]
(1 answer)
Closed 7 years ago.
I have a file in the folder like "c:\a\abc.mdb"
Sometimes someone could move it to somewhere else and leave a shortcut like "c:\a\abc.mdb.lnk".
In that case when I call IO.File.Exists(#"c:\a\abc.mdb") it still return true. In that case how can I verify if the real file exists, or whether the situation is:
abc.mdb exists only
abc.mdb.lnk exists only
or both of them exists?

How can I remove all records from a table? [duplicate]

This question already has answers here:
Entity Framework. Delete all rows in table
(25 answers)
Closed 9 years ago.
I want to delete all records from my SQL Server table. I use LINQ to EF5. Is there anything I can do to do that?
context.Entities.DeleteAllOnSubmit(dc.Entities);

Check the SQL Server database & table size [duplicate]

This question already has answers here:
Determine SQL Server Database Size
(8 answers)
Closed 9 years ago.
How can one check the SQL Server database and table size (in MB) using C#?
Have you looked at the sp_spaceused stored procedure?
Just execute it with DBName.Tablename.
Here is the MSDN Link

Is there a get-or-create (lazy loading?) idiom in SQL? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Solutions for INSERT OR UPDATE on SQL Server
Check if a row exists, otherwise insert
I'm using SQL Server 2008 R2, C# .NET 4.0 (and LINQ).
I want to get or create a row in a table and then append a string to one of its columns.
I'm wondering if there's a best practice for this kind of idiom, or if SQL offers this out of the box?
Somehow transaction start -> select -> insert or update -> transaction end doesn't seem elegant enough...

Categories