473,545 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Database quandaries...


Okay, please forgive me but I need to ask this... I went to Google and
pressed the button etc. first, really, before I asked... lol

I'm familiar with database manipulation in C++/MFC. I noticed right away,
though, that in C# if you're not wanting to use a databound control, there
seems to be little info out there on using a database. IOW, if I want to
page through a record set, select certain fields, edit, add records, like I
can in MFC, how to do this?

Almost all the tutorials I come across tout the abiilty to do stuff "without
writing any code". Well darn it, I want to write some code and I'd like to
know how.

FWIW I find C# difficult to comprehend at times. Well, not comprehend, but
difficult to use. Most of the material I've found on the 'net deals with
NOT coding, and I'm still looking for materuial that would be useful for a
MFC/C++ programmer to translate their skills to C#.
Also, here's a real dumb question: How do I *create* a SQL database? I am
used to using MS Access 2000 to build my database, and then using it in my
MFC program. How do you do the initial building for SQL? I am a bit
confused as to how to access a SQL server in VS2005 as well, i.e how do I
connect to it? And again, where can I find the right instructional material
to guide me?

TIA
B

Jun 15 '06 #1
1 1028


"saywhat" <no@fuk.no> wrote in message news:Ua******** *****@fe03.lga. ..

Okay, please forgive me but I need to ask this... I went to Google and
pressed the button etc. first, really, before I asked... lol

I'm familiar with database manipulation in C++/MFC. I noticed right away,
though, that in C# if you're not wanting to use a databound control, there
seems to be little info out there on using a database. IOW, if I want to
page through a record set, select certain fields, edit, add records, like
I can in MFC, how to do this?

Almost all the tutorials I come across tout the abiilty to do stuff
"without writing any code". Well darn it, I want to write some code and
I'd like to know how.

FWIW I find C# difficult to comprehend at times. Well, not comprehend,
but difficult to use. Most of the material I've found on the 'net deals
with NOT coding, and I'm still looking for materuial that would be useful
for a MFC/C++ programmer to translate their skills to C#.
Also, here's a real dumb question: How do I *create* a SQL database?
No dumb questions, only dumb people afraid to ask them. :-)
I am used to using MS Access 2000 to build my database, and then using it
in my MFC program. How do you do the initial building for SQL?
The best bet is to connect to a server and issue a DDL command to create the
database, along with the statements necessary to create the tables, etc. If
this is an undoable option, create the database file in SQL Server and
detatch it. You can then copy to the correct server and run sp_attachdb to
attach it. It really depends on how "on the fly" the creation is as to how
useful this option is. A good primer on T-SQL will give you the proper DDL
for object creation. BTW, the SQL books online are excellent.
I am a bit confused as to how to access a SQL server in VS2005 as well,
i.e how do I connect to it?
As you are less familiar with drag and drop (a good thing), I would examine
the actual objects in the SQL Client namespace. The help file has a great
deal of code to show you how to do things. My general pattern is something
like this:

//Look for connection strings on google
//I think the site is http://www.connectionstrings.org, but not sure
string connString = "connection string here";
string sql = "name of sproc or dynamic, parameterized sql";

/*
NOTE:
"SELECT * FROM CustomersWHERE Col1 = @Col1"
is a parameterized query.
*/

SqlConnection conn = new SqlConnection(c onnString);
SqlCommand cmd = new SqlCommand(sql, conn);

//if stored proc, you need to have this
cmd.CommandType = CommandType.Sto redProcedure;

//Either way, use something like this
SqlParameter param = new SqlParameter("@ Col1", valueHere);
cmd.Parameters. Add(param);

//for a simple update
try
{
conn.Open();
cmd.ExecuteNonQ uery();
}
finally
{
conn.Dispose();
}

For a DataSet fill you will want to create a DataAdapter and table map:

SqlDataAdapter da = new SqlDataAdapter( cmd);
da.TableMapping s.Add("Table", "Customers" );

//And you need a DataSet
DataSet ds = new DataSet("OrderI nfo"); //made up the name

//This goes inside the try {}
da.Fill(ds);
And again, where can I find the right instructional material to guide me?


Not sure if there is a "How to code C# fcor MFC Dummies" tutorial, so I
can't help you there. :-)

MSDN has the best stuff, if you want volume. There are some other
communities, but the MSDN articles are often written by the architects of
the languages, etc.

--
Gregory A. Beamer

*************** *************** *************** ****
Think Outside the Box!
*************** *************** *************** ****
Jun 15 '06 #2

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

Similar topics

0
3316
by: Cherrish Vaidiyan | last post by:
sir, The following are the steps that i followed in setting up standby database on Red hat Linux 9. i am using Oracle 9i. i have followed the steps in this site : http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96653/create_ps.htm#66206 Still i give the steps i followed. Preparing the Primary Database for Standby...
6
7311
by: Marvin Libson | last post by:
Hi All: I am running DB2 UDB V7.2 with FP11. Platform is Windows 2000. I have created a java UDF and trigger. When I update my database I get the following error: SQL1224N A database agent could not be started to service a request, or was terminated as a result of a database system shutdown or a force command.
8
7886
by: Kamlesh | last post by:
Hi, How do I know the physical database path of a database. When I goto the DB2INSTANCE users's directory (/home/db2inst1), I see following folders: /db2inst1/NODE0000/SQL00001 /db2inst1/NODE0000/SQL00002 /db2inst1/NODE0000/SQL00003 /db2inst1/NODE0000/SQL00004
1
5952
by: pintur | last post by:
The message is: SQL1036C Errore di I/O durante l' accesso al database. SQLSTATE=58030 what is the proble? what for restore tables? thanks
3
2926
by: josh.kuo | last post by:
Sorry about the subject, I can't think of a better one. I recently wrote some PHP classes that I think might be of interest to this group. Since I have been reaping the benefits of reading news groups for years, I figure it's time for me to contribute a little bit back, maybe some people out there will find this useful. * Introduction ...
8
4120
by: morleyc | last post by:
Hi, until recently i was quite happy to add data sources from mssql database in visual studio and drag the datasets directly onto the form this creating a directly editable form which worked well. However i have recently started a project which will require synchronization to a remote database. Also the underlying database provider may...
0
3293
by: Jack | last post by:
Training Classes for Oracle10g, 9i, 8i Certification training in Oracle10g and 9i: DBA, Developer, Discoverer. training conducted at your location worldwide. Courseware licensing also available. http://a.uuload.com/Oracle-Database.htm Unlock the Value of Your IT System Confio Software's Ignite for Oracle uses wait-event analysis to...
0
3271
by: Winder | last post by:
Training Classes for Oracle10g, 9i, 8i Certification training in Oracle10g and 9i: DBA, Developer, Discoverer. training conducted at your location worldwide. Courseware licensing also available. http://a.uuload.com/Oracle-Database.htm Unlock the Value of Your IT System Confio Software's Ignite for Oracle uses wait-event analysis to...
0
2537
by: Laurynn | last post by:
# (ebook - pdf) - programming - mysql - php database applicati # (Ebook - Pdf)Learnkey How To Design A Database - Sql And Crystal Report # (ebook-pdf) E F Codd - Extending the Database Relational Model to Capture More Meaning (1979) # Addison Wesley - Database Design for Mere Mortals chm # Addison Wesley - Refactoring Databases Evolutionary...
0
7478
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7410
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7668
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7923
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7773
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5984
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5343
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3466
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.