Simple question about SQL

O

ofiras

Hii everyone,
I have a basic simple question, that I coulde't find the answer for:
How can I query from a db with SQL?
I know SQL, and if I want to send a query like this: "SELECT * FROM
tablename" - how can I do it? Do I need to open the db too (like in
php)?
Please help,
Ofir.
 
N

Nicholas Paldino [.NET/C# MVP]

Ofir,

No, as long as you have a connection (which you use with the
SqlConnection class in the System.Data.SqlClient namespace in .NET), all you
have to do is make sure that it is open.

Hope this helps.
 
P

pvdg42

ofiras said:
Hii everyone,
I have a basic simple question, that I coulde't find the answer for:
How can I query from a db with SQL?
I know SQL, and if I want to send a query like this: "SELECT * FROM
tablename" - how can I do it? Do I need to open the db too (like in
php)?
Please help,
Ofir.
It would be relatively simple if you'd mentioned a context. What version of
..NET are you using? Which version of Visual Studio (if you are using Visual
Studio)? What database? Windows or web app? The answer will differ
considerable depending on these factors. In general, yes, you must establish
a connection to the database.
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

ofiras said:
I have a basic simple question, that I coulde't find the answer for:
How can I query from a db with SQL?
I know SQL, and if I want to send a query like this: "SELECT * FROM
tablename" - how can I do it? Do I need to open the db too (like in
php)?

Do you have a book on C# ?

Try and find the chapter about ADO.NET !

At the 30000 feet level it is not that different from PHP.

Arne
 
O

ofiras

Thenks all,
I found out how to do it...
This is the exemple:

using System;
using System.Data;
using System.Data.OleDb;
namespace ADONETWriteQuery
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
static void Main(string[] args)
{
string strDSN = "Provider=Microsoft.Jet.OLEDB.4.0;DataSource=c:\
\mcTest.MDB"; string strSQL = "INSERT INTO Developer(Name, Address )
VALUES('NewName', 'NewAddress')" ;
// create Objects of ADOConnection and ADOCommand
OleDbConnection myConn = new OleDbConnection(strDSN);
OleDbCommand myCmd = new OleDbCommand( strSQL, myConn );
try
{
myConn.Open();
myCmd.ExecuteNonQuery();
}
catch (Exception e)
{
Console.WriteLine("Oooops. I did it again:\n{0}", e.Message);
}
finally
{
myConn.Close();
}
}
}
}

Thenks a lot,
Ofir.
 
O

ofiras

Hmm... I have another question - Why cant I create data connection to
a DB I get from my web hosting? is it just me or no one can?
Please help,
Ofir.
 
V

Victor Rosenberg

Hmm... I have another question - Why cant I create data connection to
a DB I get from my web hosting? is it just me or no one can?
Please help,
Ofir.

What do you mean by getting a db from web hosting?
 
O

ofiras

What do you mean by getting a db from web hosting?

For exemple, I use http://www.ifastnet.com/ to host websites I did,
and when I sign, it gives me free DB on their server.
I tried to make a data source from this DB, but when I get to the
phpMyAdmin It says "The HTML document does not contain Web service
discovery information.". Can you tell me about a free SQL hosting that
actualy works?
Thenks,
Ofir.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top