Re: Database quandaries...

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance





"saywhat" <no@xxxxxx> wrote in message news:Uackg.69$_r4.13@xxxxxxxxxxx

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!
*************************************************


.



Relevant Pages

  • RE: Backups have Shadow Copy Problems
    ... and restarted the server. ... suggested and changed the recovery model to simple on the one database called ... I understand the issue to be: the backup task failed ... You back up data from a volume that contains a Microsoft SQL Server ...
    (microsoft.public.windows.server.sbs)
  • Re: upsizing to sql 2005
    ... the word SERVER in it, ... You can access to the database by multiple means (Access, ... and how does it update the SQL database with the new records in Access? ... Query Name: Arcadia - ARC ...
    (microsoft.public.access.queries)
  • Re: Linked Tables in Access
    ... any use of SQL Passthru, Linked Tables or any other use of MDB / MDE ... server, or would I also need to convert *those* queries to passthrough ... I've been trying to understand why Access database files become corrupt. ...
    (microsoft.public.access.adp.sqlserver)
  • Re: Leveling by ID vs. "Standard"
    ... of this trade called Project Management. ... a database for the "Project Tables," ... to write reports on data from the server database. ... product supporting queries created with SQL. ...
    (microsoft.public.project)
  • Re: Trouble Getting VS.Net 2003 WalkThroughs MSDE Connection
    ... Config Tool of SQL Server? ... > link to download the PUBs database. ... >>> Setup and they directed me to install MSDE and they attached a ...
    (microsoft.public.sqlserver.msde)