 |
|
 |
Apologies for the shouting but this is important.
When answering a question please:
- Read the question carefully
- Understand that English isn't everyone's first language so be lenient of bad spelling and grammar
- If a question is poorly phrased then either ask for clarification, ignore it, or mark it down. Insults are not welcome
- If the question is inappropriate then click the 'vote to remove message' button
Insults, slap-downs and sarcasm aren't welcome. Let's work to help developers, not make them feel stupid.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
 |
|
 |
For those new to message boards please try to follow a few simple rules when posting your question.- Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
- Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
- Keep the subject line brief, but descriptive. eg "File Serialization problem"
- Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
- Be careful when including code that you haven't made a typo. Typing mistakes can become the focal point instead of the actual question you asked.
- Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
- If you are posting source code with your question, place it inside <pre></pre> tags. We advise you also check the "Encode "<" (and other HTML) characters when pasting" checkbox before pasting anything inside the PRE block, and make sure "Use HTML in this post" check box is checked.
- Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
- Please do not post links to your question into an unrelated forum such as the lounge. It will be deleted. Likewise, do not post the same question in more than one forum.
- Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
- If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
- No advertising or soliciting.
- We reserve the right to move your posts to a more appropriate forum or to delete anything deemed inappropriate or illegal.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
 |
|
 |
If you are doing an inner join does it matter which order the tables are in?
Is
Table1 inner join Table2
any different from
Table2 inner join Table1
Could there be any difference?
Brent
|
|
|
|
 |
|
 |
No, there cannot be. It just means rows between the two tables with the same value in the 'joined' columns. So the order in which the table names are mentioned doesn't matter.
However, for Right and Left joins, it does matter.
|
|
|
|
 |
|
 |
Hi all.
I'm now developing a website that connect to Postgre SQL database. I used NpgSQL.DLL to connect from C# to database. I also finished testing this project in my local pc, it worked well. But unfortunately it did not work well in server. Some errors in connecting to server happened.
These errors happened when website had much people logged in and began using database query functions ( select, update, delete .. ). I think errors begin from codes in connect database functions. but i still can not fix it. this is my connecting database codes.
------ codes connects database ---------
-- Connect.cs file.
public static void connectDB()
{
try
{
conn.ConnectionString = connection;
conn.Open();
}
catch
{
}
}
public static void closeConnectDB()
{
conn.Close();
}
public static int ExecuteQuery(string SQL)
{
try
{
connectDB();
NpgsqlCommand cmd = new NpgsqlCommand(SQL, conn);
return cmd.ExecuteNonQuery();
}
catch
{
closeConnectDB();
return 0;
}
}
public static DataSet SelectQuery(string SQL)
{
DataSet ds = new DataSet();
try
{
connectDB();
NpgsqlDataAdapter nDa = new NpgsqlDataAdapter(SQL, conn);
nDa.Fill(ds);
return ds;
}
catch
{
closeConnectDB();
return ds;
}
}
----------------- use to execute these codes --------
....
--- calling functions files.
try
{
string strTest = "Select * from abc where .. ";
DataSet ds1 = new DataSet();
ds1 = Connect.SelectQuery(strTest);
if (ds1.Tables[0].Rows.Count > 0)
{
}
else
{
int kq = Connect.ExecuteQuery(strInsert);
if (kq > 0)
{
int kk = Connect.ExecuteQuery(strUpdate);
kk = Connect.ExecuteQuery(strUpdate2);
strHTML = "OK";
}
}
}
catch
{
strHTML = "errors.";
}
finally
{
int kk = Connect.ExecuteQuery(strUpdate);
kk = Connect.ExecuteQuery(strUpdate2);
strHTML += "-- Sub Finally";
}
-----------------End calling function---------------
Here sometimes it worked well but sometimes catched errors.
Can you help me? thanks and regards.
|
|
|
|
 |
|
 |
Looking at your code, I can't help but think you're being hammered because you have static methods in a multi user system, and the code isn't thread safe. In other words, you have static variables (take a look at your connection variable), and you are opening and closing them without any form of synchronisation in place. In other words, you could have two users both "open" a connection at the same time, and then one finishes and closes the connection before the other one completes.
The easiest fix is to move the open and close logic into the other methods, rather than relying on member variables.
|
|
|
|
 |
|
|
 |
|
 |
stop your static abuse, and start using the using construct[^], it fits quite well in DB applications.
|
|
|
|
 |
|
|
 |
|
 |
Hi everyone,
I want to make a library project,I have made this model and I have a question is this a correct desgin for implementation or no
Main table is Books I have these fields on it
Book ID Bookname Title publish year description ISBN
Authors table
Book ID author name phone address email
publishers table
BookID publisher name phone address email
BookID's are primary key in this databse and I am going to use of it for relationship
is this a correct design and do I need to insert anything?
Thanks
|
|
|
|
 |
|
 |
messages wrote: question is this a correct desgin for implementation or no
Instead of having each design validated here, you could use the normalization-rules and validate it yourself.
Bastard Programmer from Hell
|
|
|
|
 |
|
 |
could you help me ,please I have read normalization-rules I want only know is this correct or it has problem(I mean is your sentence).I have almost like this problem I want to know do I need to normalization-rules no?
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
 |
|
 |
Hamid. wrote: I have almost like this problem I want to know do I need to normalization-rules no?
If you want a decent relational model, then it would be wise to normalize them, at least up to 3NF. You can "prove" that your model is in 1NF by checking the five conditions mentioned on the Wikipedia[^].
I know that you're looking for a yes/no answer, but that's not good enough. If things go wrong you're not helped much by shouting that "Eddy" told you that your model is right/wrong. You want to be able to defend your model, as opposed to taking the word of a stranger.
Bastard Programmer from Hell
|
|
|
|
 |
|
 |
I don't think "book ID" is a good name for the primary key of an authors table.
|
|
|
|
 |
|
 |
Yeah I think ISBN is a good idea.
|
|
|
|
 |
|
 |
Your structure is quite incorrect. Think about 1 to many and ask these questions.
Does a publisher publish only 1 book?
Does and Author ALWAYS only write 1 book?
Does a book ALWAYS have only 1 author.
Go follow Eddies suggestion, it will help you understand the basics.
Never underestimate the power of human stupidity
RAH
|
|
|
|
 |
|
 |
Thanks for your answer I have read wikipedia 1NF,....but how can I those rules in my project, I need to have a clear idea to write let me explain in this way
(1)we have some publishers
(2)we have some authors
publishers publish different books of different authors so we need to three tables(publisher,author and book) I guess that they should have a many to many relationship is it correct?
could you tell me please how can I implement relationships between these tables?
Thanks
|
|
|
|
 |
|
 |
Now you are getting the idea.
You need Link tables
lnkPublisherBook
LinkID
BookID
PublisherID
lnkAuthorBook
LinkID
BookID
AuthorID
Never underestimate the power of human stupidity
RAH
|
|
|
|
 |
|
 |
Thanks for your help may I ask my questions in the future?
|
|
|
|
 |
|
 |
Never stop asking questions, just make sure you have thought about the questions you are asking. ALWAYS do some research before dumping it into the forum, especially as you are learning. Almost every question you can come up with will have already been asked many times.
Never underestimate the power of human stupidity
RAH
|
|
|
|
 |
|
 |
Hi again
I have made this schema,is this correct(its my first question)
LogIn table
user_name(primary key) password AuthorID(Foreign key) PublisherID(foreign key)
Publishers table
publisherID(primark key) publisher name phone address (and other fields)
Authors table
AuthorID(primary key) Author name phone address publisherID(Foreign key) (and other fields)
Books Table
BookID(primary key) Book name Year Title (and other fields)
and its my second question I thought to make this table for AuthorBook
AuthorBook table
AuthorBookID(primary key) AuthorID(Foreign key) BookID(Foreign key)
Do I need to Foreign key in Authors table or Book tables?
Thanks
|
|
|
|
 |
|
 |
Don't you think an author might publish different books via different publishers?
messages wrote: Do I need to Foreign key in Authors table or Book tables?
You should always use foreign keys in your tables whenever possible. It lowers the risk of corruption.
BTW, you're having a good naming standard for your fields.
|
|
|
|
 |
|
 |
Thank you for your help so my code is good and I need only to insert foreign key to Authors,right?
Thanks again
|
|
|
|
 |
|
 |
It's ok so far, but you're not ready yet.
To clarify what I mentioned in my previous message, is that I doubt that it's correct that the Authors table is having the field PublisherID in it. As an author might choose to publish different books at different publishers.
I would argue that you need another link table, the BookPublisher table.
|
|
|
|
 |
|
 |
I am having such a hard time writing a SQL query. Can someone please look over this query and see where am I going wrong?
I will be using the XML elements to describe the table even though I am using SQL Server 2008 R2..
<vPSR>
<ProjectID/>
<ReportMonth Comment="2 digit Month. (MM)" />
<ReportYear Comment="4 digit Year. (YYYY)" />
</vPSR>
Here is an example of the data that is listed.
ProjectID ReportMonth ReportYear
1000700 05 2008
1000700 06 2008
1000700 07 2008
1000700 12 2008
1000700 01 2009 <-- I want the query to find this! Even though the Month is not the max value, but the Year is the Max value.
Here is what I have so far. Where am I going wrong?
SELECT vPSR.ProjectID, vPSR.ReportMonth, vPSR.ReportYear
FROM vPSR
WHERE vPSR.ReportMonth =
(SELECT MAX(ReportMonth)
FROM vPSR AS f
WHERE f.ProjectID = ProjectID
AND ReportYear =
(SELECT MAX(ReportYear)
FROM vPSR AS k
WHERE k.ProjectID = vPSR.ProjectID))
ORDER BY vPSR.ProjectID ASC
I got the idea on how to write the above query here.[^] I don't understand it that well.
If you need me to clarify anything please do not hesitate to ask.
|
|
|
|
 |