473,474 Members | 1,852 Online
Bytes | Software Development & Data Engineering Community
Create 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 1025


"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(connString);
SqlCommand cmd = new SqlCommand(sql, conn);

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

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

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

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

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

//And you need a DataSet
DataSet ds = new DataSet("OrderInfo"); //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
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 : ...
6
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...
8
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...
1
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
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...
8
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....
0
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....
0
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....
0
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...
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
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
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,...
1
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.