|
General rule: Go for a query when you are doing something quick and dirty. Go for a stored procedure in all other circumstances.
|
|
|
|
|
SPs are the best for your db an sql: 1) less traffic on your network 2) best performance on your db 3) encapsulation and security are easier to manage.
|
|
|
|
|
Am retrieving data from my databese engine to read the data, but encountering an error at dr.Read(), con.close()
string connection=@" ";
SqlConnection con = new SqlConnection(connection);
SqlCommand cmd = new SqlCommand("select * from employee",con);
SqlDataReader dr = cmd.ExecuteReader();
dr.Read();
con.Close();
"Invalid token '(' in class, struct, or interface member declaration", what could be the reason for this?
-- modified at 18:57 Friday 9th February, 2007
|
|
|
|
|
sreecahitu wrote: Invalid token '(' in class, struct, or interface member declaration
I don't know why that error occurs. There is not enough information given.
However, I can point out other problems with the code.
1. The connection string is empty (although I'm guessing you removed it for security)
2. You never open the connection.
3. You read from the database but you never check if anything exists, and if it does exist you never actually get the data.
|
|
|
|
|
Hello everyone
I wanted to ask if we can update the column values automatically?
my requirement is a particular column value of a table should get changed when the system time is changed
can this be done in T-sql?
Please reply its very urgent thank you
|
|
|
|
|
Ravi Ahuja wrote: my requirement is a particular column value of a table should get changed when the system time is changed
can this be done in T-sql?
Given that the system time is changing continuously, no.
What exactly is your objective? There might be a better way of thinking about the problem.
|
|
|
|
|
my objective say when the system date changes say today is 02/11/2007 so when the date will change to 02/12/2007
the column value should change.
see basically i am working on a ticket reservation project
so when a ticket is issued to a customer his status is set to confirmed or waiting depending upon the situation
and when the train departs than his status must change as departed
|
|
|
|
|
Ravi Ahuja wrote: so when a ticket is issued to a customer his status is set to confirmed or waiting depending upon the situation
and when the train departs than his status must change as departed
And you are saying that a train has departed based on the time, rather than whether the train actually departed or not.... Interesting system...
I suggest you need to find a way to be told that a train actually departed rather than when you expected the train to depart (if at all)
|
|
|
|
|
I have to make questions like this:
CString abfrage;
abfrage = "SELECT kstnr, kststamm.Bezeichnung, karnr, KarBezeichnung, buchungen.ktrnr, KtrBezeichnung, betrag, datum, datenart, belsymbol,\
belnr, text FROM buchungen LEFT OUTER JOIN karstamm ON buchungen.karnr = karstamm.Nummer ";
abfrage = abfrage + "LEFT OUTER JOIN kststamm ON buchungen.kstnr = kststamm.Nummer ";
abfrage = abfrage + " LEFT OUTER JOIN ktrstamm ON buchungen.ktrnr = ktrstamm.KtrNr WHERE datum >= ";
abfrage = abfrage + "'" + kstvon.c_str() + "' AND datum <= '" + kstbis.c_str() + "'";
if (kstnr != "") abfrage = abfrage + " AND kstnr = '" + kstnr.c_str() + "'";
if (koarnr != "") abfrage = abfrage + " AND karnr = '" + koarnr.c_str() + "'";
if (datenart != "") abfrage = abfrage + " AND datenart = '" + datenart.c_str() + "'";
rs->Close();
rs->Open(CRecordset::snapshot, abfrage);
Is there an easier way to make a Select in VC++??
I made this question in the Longe, unforounatly - and my question was even deleted (what's right, wrong click;))
But can anyone help here???
Thanks, Gerhard
|
|
|
|
|
Your question is not 100% on this forum again;)
anyway I forgot sql server but I think its possible can you create a view on your database and use of it on the VC++?and also you can use of CString::Insert instead abfrage = abfrage + ...;)
|
|
|
|
|
Tahnks,
Seems to be a good idea.
Can you tell me, what would be the right forum for a question like this. Lounge was a fault, of course - sorry.
Gerhard
|
|
|
|
|
Your're welcome
Well Lounge was 100% fault.No programming questions please (on the Lounge);)
Why you cant find MFC forum (Visual C++ / MFC) Visual C++ / MFC[^]
|
|
|
|
|
Becouse I opened the menue-point 'Message Boards' and searched there. And there it's called Visual C++ only.
But I already found, thanks
|
|
|
|
|
Not problem maybe you are new here(codeproject),but I am ready to help people
|
|
|
|
|
Try the CString::Format member.
Here is what with ADO and MFC:
CString tempStr;
try {
tempStr.Format("SELECT * "
"FROM CAD_Info "
"WHERE ( ([SessionNumber] = %d) "
"AND ([SiteID] = %d) "
"AND ([SeqNumber] = %d) )",
nSession,nSiteID,nSeqNum);
CMainDataBase::TESTHR(pRst.CreateInstance(__uuidof(Recordset)));
CADORecordSetEx rst(m_pDB,pRst);
rst.Open(tempStr,m_cursorType,m_lockType, adCmdText);
}
catch(CException* e)
{
}
catch (...)
{
}
I know you are using CRecordSet and DAO but the syntax should be similar.
John
|
|
|
|
|
Thanks for the answer,
Unfortunatly I have no experience with ADO, but I have some books to learn it. Maybe I have to do so now;)
BTW, the statemant above ment, this is not the rigth forum too. What would be the right one. In the Lounge ( sorry again), you said, I should try in the MFC-forum, but I can't find.
Thanks, Gerhard
|
|
|
|
|
ensger wrote: this is not the rigth forum too. What would be the right one.
1: Querying the database in the manor you are, your exposing the database to SQL injection attacks. See this article for help distinguishing these attacks.
SQL Injection Attacks[^]
2: Looks like you where suggested to ask this question in the MFC forum was because it’s all string manipulation. Which falls under the purview of MFC CString, although for the purposes here it’s really fine in either forum.
ensger wrote: I should try in the MFC-forum, but I can't find.
Visual C++ / MFC[^]
Good Luck
I'd love to help, but unfortunatley I have prior commitments monitoring the length of my grass. :Andrew Bleakley:
|
|
|
|
|
Seems to be a very interesting article.
Thaks, Gerhard
|
|
|
|
|
ensger wrote: nfortunatly I have no experience with ADO, but I have some books to learn it.
I recommend ADO if you plan on writing SQL code for connecting to a MS SQL server (or the free version of that) as it is much better at that task and it works well with multithreading which with DAO you have to be very careful.
Although I do not use this code I recommend this class for connecting to ADO databases:
http://www.codeproject.com/database/caaadoclass1.asp[^]
John
|
|
|
|
|
|
Sorry. I was very busy at work. I had 2 doctors in and I had to demo my software to them and I also interviewed someone for a programming position all this while rebuilding a raid array on a linux box.
John
|
|
|
|
|
Thank you for your answer above.
My posting was realy just a question - not a reminder;)
And sometimes I forget, that when I'm working, you may sleep and when I'm sleeping, you may work. That's a problem of internet - you don't recognice the time of others you are speeking to.
Thanks again, Gerhard
|
|
|
|
|
I know this solution is out there somewhere but I have not been able to track it down so here is the situation. I am creating a database and tables dynamically at runtime and I need to verify that the database and table do not already exist on the SqlServer2005 database.
Any takers
_____________________________________________________________________
Our developers never release
code. Rather, it tends to escape, pillaging the countryside all around.
The Enlightenment Project (paraphrased comment)
Visit Me at GISDevCafe
|
|
|
|
|
Connect to the master database (which always exists) and check the sysdatabases table (Actually, that might have changed in 2005)
[ADDITIONAL]
It does exist, but as a backwards compatibility option for SQL Server 2000.
The new way is to use the sys.databases view
[/ADDITIONAL]
|
|
|
|
|
From what I have read connecting to the sysdatabases is bad practice as these can change. After a little more research I discovered that in 2.0 there is a connection.getschema method that will return a datatable of the schema of the server. Furthermore, this takes various parameters and to get the database I just have to pass it a string "Databases" to get a table of database names. Rather nifty, maybe Ill write an article.
Aaron
_____________________________________________________________________
Our developers never release
code. Rather, it tends to escape, pillaging the countryside all around.
The Enlightenment Project (paraphrased comment)
Visit Me at GISDevCafe
|
|
|
|