473,396 Members | 1,706 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,396 software developers and data experts.

Simple question about SQL

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.

Apr 8 '07 #1
9 1308
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"ofiras" <of****@gmail.comwrote in message
news:11**********************@n76g2000hsh.googlegr oups.com...
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.

Apr 8 '07 #2

"ofiras" <of****@gmail.comwrote in message
news:11**********************@n76g2000hsh.googlegr oups.com...
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.
Apr 8 '07 #3
ofiras wrote:
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
Apr 8 '07 #4
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.

Apr 8 '07 #5
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.

Apr 8 '07 #6
On Apr 8, 10:13 pm, "ofiras" <ofi...@gmail.comwrote:
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?

Apr 8 '07 #7
"Victor Rosenberg" <Vi**************@gmail.comwrote in message
news:11**********************@w1g2000hsg.googlegro ups.com...
On Apr 8, 10:13 pm, "ofiras" <ofi...@gmail.comwrote:
>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?
Presumably, he means the database that he gets from his web hosting
company...
Apr 9 '07 #8
On Apr 8, 11:00 pm, "Victor Rosenberg" <Victor.Rosenb...@gmail.com>
wrote:
On Apr 8, 10:13 pm, "ofiras" <ofi...@gmail.comwrote:
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?
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.

Apr 9 '07 #9
hi
as in php you need not have to open db side by side to query from it . you need to do is that just take sqlcommand object and pass the connection string to it and various parameter then open connection and retrive your query output

EggHeadCafe.com - .NET Developer Portal of Choice
http://www.eggheadcafe.com
Apr 11 '07 #10

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

Similar topics

11
by: JKop | last post by:
Take the following simple function: unsigned long Plus5Percent(unsigned long input) { return ( input + input / 20 ); } Do yous ever consider the possibly more efficent:
13
by: Michael B Allen | last post by:
Hi, I've tried to write the *simplest* memory allocator possible. I think it would be useful in many cases such as allocating memory on stack as a poor man's garbage collection perhaps. I was...
8
by: Beam_Us_Up_Scotty | last post by:
Hello all, I am trying to write a "simple" animation using C#, and I've tried many things but nothing seems to work for me without leaking memory. Here's a very simple piece of code that uses a...
2
by: Abel Chan | last post by:
Hi there, I just got an assignment to work on server maintenance. It is a weekly task and we have about 7 production servers running Win2K server. The tasks include but not limited to 1)...
7
by: abcd | last post by:
I am trying to set up client machine and investigatging which .net components are missing to run aspx page. I have a simple aspx page which just has "hello world" printed.... When I request...
10
by: serge calderara | last post by:
Dear all, I need to build a web application which will contains articles (long or short) I was wondering on what is the correct way to retrive those article on web page. In orther words, when...
10
by: Andrew | last post by:
Sorry about this but I'm new to ADO.NET (finally coming from simple ADO, bless it) and I'm trying to create a simple three tier program. Ie, User interface Layer / Business object layer / Database...
14
by: Giancarlo Berenz | last post by:
Hi: Recently i write this code: class Simple { private: int value; public: int GiveMeARandom(void);
1
by: =?ISO-8859-1?Q?Tor_Erik_S=F8nvisen?= | last post by:
Hi, A while ago I asked a question on the list about a simple eval function, capable of eval'ing simple python constructs (tuples, dicts, lists, strings, numbers etc) in a secure manner:...
17
by: Chris M. Thomasson | last post by:
I use the following technique in all of my C++ projects; here is the example code with error checking omitted for brevity: _________________________________________________________________ /*...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.