|
This is me again...
I initially started this message thread as I had a problem getting the ado connection at startup....
i had written the exe path in a key in registry
"HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\\Run"...though the exe startsup an ado connection error is thrown if ado connection is tried in InitInstance of the app
ive finally got it right..consider the following code
-----------------------------------
CoInitializeEx(NULL, 0x02);
try{
_ConnectionPtr mpDBConnection;
mpDBConnection.CreateInstance(__uuidof(Connection));
HRESULT hRes=mpDBConnection->Open(_T("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=database\\TrialDB.mdb;Persist Security Info=False"),"","",adConnectUnspecified);
CStartUpDlg dlg;
m_pMainWnd = &dlg;
...
...
..
-----------------------------------
this works fine when normally executed and the database connection is ok.
however in startup when saying "database\TrialDB.mdb" instead of refering to the relative path of the application it assumes it as being in "c:\" drive.....
and therefore looks for the database in "c:\database\TrialDB.mdb" ..
and obviously as there is no database there the connection fails.
however if the code is changed tohaving the follwoing lines occure before the connection is opened like below
-----------------------------------
CoInitializeEx(NULL, 0x02);
try{
CStartUpDlg dlg;
m_pMainWnd = &dlg;
_ConnectionPtr mpDBConnection;
mpDBConnection.CreateInstance(__uuidof(Connection));
HRESULT hRes=mpDBConnection->Open(_T("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=database\\TrialDB.mdb;Persist Security Info=False"),"","",adConnectUnspecified);
...
...
..
-----------------------------------
the conection works fine in startup as well..
but unfortunately as i need to do the database connection before I create the dialog object..... the question persists...
<b>1.Why cant i get the relative path in startup????
2.Please suggest an alternative solution to get the relative path....
i mean besides using get CurrentDirectory() and that kind of stuff </b>
Consider for example when we create a shortcut
we can specify a 'start in' directory
and all relative paths refer to this strt in directory right??
<b>is there anywhere i can specify such a 'start in' directory for an application in registry!!!</b>
if there is any other method to get the relative path of the app please tell me...
|
|
|
|
|
I am doing a join with three tables and I can't seem to get distinct rows. I know what the problem is, but I'm not enough of a SQL person to know the proper syntax. The tables are Customers, CustomerRelationships, CustomerRelationshipsLU (as in Look Up). I get the CustomerID, FirstName, and Last Name from the Customers Table. The CustomerRelationships table tells me how one customer is related to another (e.g. wife, son, etc.). I need to get the name of the relationship and not the ID which is why I am joining the CustomerRelationshipsLU table as well. Here is the statement I am using currently:
SELECT TA_Customer.Customer_ID,
TA_Customer.FirstName,
TA_Customer.LastCompanyName,
TA_CustomerRelationshipsLU.Description
FROM TA_CustomerRelationships INNER JOIN TA_CustomerRelationshipsLU ON
TA_CustomerRelationships.RelationshipID =
TA_CustomerRelationshipsLU.RelationshipID CROSS JOIN
TA_Customer
WHERE (TA_Customer.CustomerID = '101') AND (TA_CustomerRelationships.CustomerID = '101')
Youre eyes are not deceiving you--there is a CustomerID and a Customer_ID (notice the underscore _ in the second). CustomerID represents what you might think of as a customer group (e.g. family, business, etc.) whereas Customer_ID represents the individual ID for every customer--as in person.
My query returns:
155611 Jane Jones Wife
155611 Jane Jones Son
155612 Willy Jones Wife
155612 Willy Jones Son
DISTINCT doesn't help for obvious reasons. Does this make sense to anyone? Any help would be appreciated.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
yah well the point is the result set u got IS distinct if u look at all the returned fields
maybe u have to select the first part into a temp table and do a select distinct from there
"traffic lights are for people who can't make their own decisions" biz stuff about me
|
|
|
|
|
Can you provide some SQL? I'm not sure how to do what you're talking about or how it would fix my problem.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
in terms of ur above example what exactly would u want to see in the result set?
"traffic lights are for people who can't make their own decisions" biz stuff about me
|
|
|
|
|
I would like to see:
155611 | Jane | Jones | Wife
155612 | Willy | Jones | Son
Thanks.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
I think the problem you are having is the cross join on relationships. There should be no reason why you would get Jane Jones as both Wife and Son. Can you post the tables? For example, give me two or three lines of data for each of the three tables, adn I can look more closely at the query you have written.
Jeremy
Jeremy Oldham
|
|
|
|
|
Sounds good. I appreciate your help.
Here's a select on the top level CustomerID (which is '101' in this case)for the TA_Customer table (I used a reduced set of columns for brevity on this particular tables. The ones below it are, however, complete):
TA_Customer
------------
Customer_ID CustomerID LastName FirstName
155603 101 Jones Bob
155611 101 Jones Jane
155612 101 Jones Willy
TA_CustomerRelationships
-------------------------
CustomerID Customer_ID1 Customer_ID2 RelationshipID
101 155603 155611 2
101 155603 155612 3
TA_CustomerRelationshipsLU
---------------------------
RelationshipID Description
1 Husband
2 Wife
3 Son
4 Daughter
5 Father
6 Mother
7 Grandfather
8 Grandmother
9 Uncle
10 Aunt
11 Nephew
12 Niece
13 Cousin
For your convenience, here is the original query:
SELECT TA_Customer.Customer_ID,
TA_Customer.FirstName,
TA_Customer.LastCompanyName,
TA_CustomerRelationshipsLU.Description
FROM TA_CustomerRelationships INNER JOIN TA_CustomerRelationshipsLU ON
TA_CustomerRelationships.RelationshipID =
TA_CustomerRelationshipsLU.RelationshipID CROSS JOIN
TA_Customer
WHERE (TA_Customer.CustomerID = '101') AND (TA_CustomerRelationships.CustomerID = '101') AND
(TA_Customer.Customer_ID <> 155603)
Notice I added in an extra 'AND' clause. I only want to return the subordinate records. The top level record is the one for "Bob" whose Customer_ID is 155603.
As a reminder, I want the output to be this:
155611 Jane Jones Wife
155612 Willy Jones Son
Thanks for your help.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
Try the following and let me know how it worked.
<br />
Select TA_Customer.Customer_ID, TA_Customer.FirstName, <br />
TA_Customer.LastName, TA_CustomerRelationshipsLU.[Description]<br />
FROM TA_Customer<br />
INNER JOIN (<br />
--Gives you the Relationships for the individual<br />
Select Customer_ID2, RelationshipID<br />
from TA_CustomerRelationships<br />
WHERE Customer_ID1 = 155603<br />
AND CustomerID = 101<br />
) b <br />
ON TA_Customer.Customer_ID = b.Customer_ID2<br />
INNER JOIN TA_CustomerRelationshipsLU<br />
ON b.RelationshipID = TA_CustomerRelationshipsLU.RelationshipID<br />
Jeremy Oldham
|
|
|
|
|
Sheesh! Just when I think I'm starting to get better at SQL, somebody shows me a query like this. I have no idea what exactly is going on in this query, but it worked like a charm. Thank you so much for your help. I really appreciate it.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
Well let me give you a quick description.
First, I wanted to get only the customer numbers we needed that are related to the customer 155603 and is in the correct Customer Group 101. I did this be creating the following query:
--Gives you the Relationships for the individual<br />
Select Customer_ID2, RelationshipID<br />
from TA_CustomerRelationships<br />
WHERE Customer_ID1 = 155603<br />
AND CustomerID = 101
This query returns all the customers related to the Customer ID 155603 and within his group, as well as their relationship id.
Now all I needed to do is find out who those customers were (by their customer id) and what those relationships were (by relationID).
I did that by joining the TA_Customer table with the subquery which gives me the related customers information, and then joining the TA_CustomerRelationshipsLU table with the subquery which gives me the relation names.
I hope this helps explain the query a little bit.
Glad I could be of help!
Jeremy Oldham
|
|
|
|
|
Howdy all,
I'm using C# and ADO.NET to access an SQL Server Database, using SqlDataAdapter, DataSet et al.
What I want to do is create a new row, submit it to the database, and then retrieve the Identity field that SQL Server automagically generates. At the moment I have something like this:
string comm_str = String.Format( "SELECT Name, Image, IllustrationID FROM Illustrations");
SqlCommand comm = new SqlCommand( comm_str, m_sqlConn );
SqlDataAdapter da = new SqlDataAdapter( comm );
da.InsertCommand = da.SelectCommand.Connection.CreateCommand();
da.InsertCommand.CommandText =
@"INSERT INTO Illustrations (Name, Image) values(@Name, @Image)";
da.InsertCommand.Parameters.Add( "@Name", SqlDbType.Char, 0, "Name" );
da.InsertCommand.Parameters.Add( "@Image", SqlDbType.Image, 0, "Image" );
DataSet ds = new DataSet();
da.Fill( ds, "Illustrations" );
DataTable dt = ds.Tables["Illustrations"];
DataRow newRow = dt.NewRow();
newRow["Name"] = name.Length;
newRow["Image"] = imageBuffer;
dt.Rows.Add( newRow );
da.Update( ds, "Illustrations" );
ds.AcceptChanges();
newImageID = (int)newRow["IllustrationID"];
Now I think this code may look a little naieve, as I've cobbled it together from various books, but it does the job, apart from retrieving the IllustrationID field from the new record.
IllustrationID is set as an Identity field in the DB, so when a new record is inserted a value is generated by the DB. I'm guessing I need to update my DataSet, but I'm not sure how. Also, after updating my DataSet do I need to get a new DataTable, etc. or is this all handled automagically by ADO.NET.
Hope that makes some kind of sense and that someone has some advice for me!
TIA,
Pete
|
|
|
|
|
if ur using sql server u can use @@identity to get the last inserted record's id
"traffic lights are for people who can't make their own decisions" biz stuff about me
|
|
|
|
|
I'm really looking for a solution using the C# DataAdapter and DataSet classes.
Thanks anyway
|
|
|
|
|
If you use a proper DataSet definition (Project->Add New Item, select DataSet, rename it, OK, drag-drop an element "Illustrations", add all your fields as sub-elements of that) then you can define one of those fields as AutoIncrement. Then it does all the work for you.
Paul
Pleasently caving in, I come undone - Queens of the Stone Age, No One Knows
|
|
|
|
|
Would that work with multiple users?
Say the last inserted record had an ID of 34, and user A gets his DataSet and inserts the record. meanwhile user B has inserted a record. if User A then checked the ID field would it be 35 or 36?
does that make sense?
|
|
|
|
|
In case anyone else needs help with this, there is a good article
HTH,
Pete
|
|
|
|
|
Is it possible to use ADO.NET from unmanaged c++?
Cheers,
Clint
|
|
|
|
|
Hi all, Got a bit of a problem here, I'm using C#/ASP.NET and am attempting to connect to a SQL source, wich is located on a server(SILICON) I have used the below connection syntax:
String strConnection = "server=SILICON; database=PositonTracker01; integrated security=true;";
SqlConnection objConnection = new SqlConnection(strConnection);
String strSQL = "SELECT FirstName, LastName, Country " + "FROM Analyst";
SqlCommand objCommand = new SqlCommand(strSQL, objConnection);
when i run this I get no data, just my html layout minus the data it should show, any suggestions?
|
|
|
|
|
- You've created a
SqlConnection object, but never opened it; - You've created a
SqlCommand object, but never executed it; - You haven't added any code to output the results of the query;
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
|
|
|
|
|
<%@ Import namespace="System.Data" %>
<%@ Import namespace="System.Data.SqlClient" %>
<title>Authorised Users
TEST
<asp:datagrid id="dgNameList"
="" runat="server" gridlines="None" backcolor="LightBlue" cellpadding="5" cellspacing="5" borderwidth="2" bordercolor="Black" <="" body="">
private void Page_Load(object sender, System.EventArgs e)
{
String strConnection = "server=SILICON; database=PositonTracker01; integrated security=true;";
SqlConnection objConnection = new SqlConnection(strConnection);
String strSQL = "SELECT FirstName, LastName, Country " + "FROM Analyst";
SqlCommand objCommand = new SqlCommand(strSQL, objConnection);
objConnection.Open();
dgNameList.DataSource = objCommand.ExecuteReader();
dgNameList.DataBind();
objConnection.Close();
}
|
|
|
|
|
|
I'm creating a login system and I am wondering about the design i have chosen because it seems to be counter productive. Basically I have 2 tables as it stands:
BTW - MEID is members id, AUTHID is auth_users id
1) auth_users
2) members
- PKID
- AUTHID
- EMAIL
- FNAME
- LNAME
- NLOGINS
- OPTIONS
- LASTLOGIN
- EXPIRES
Anyways, initially the login required me querying only the auth_users table, but that changed when features were added. Like account expiration, number of logins, last login time and date, account privileges, etc. So my question is this, should I sticj with the current design and basically run two queries at login (login permission is cached in a cookie, so once you've logged in the system won't bother you again, nor will it run the query to authenticate users)?
Should I maybe add the required fields to the auth_users table instead of keeping them in the members table so I only have to run one query at login or should I keep it as is so I have to run 2 queries at login?
Thanks
"Two wrongs don't make a right, but three lefts do!" - Alex Barylski
|
|
|
|
|
May I suggest a 3rd option?
Use 2 tables. Combine the auth_users and members table. Add a new table called user_props. user_props will need 3 columns.
pkid (ref auth_users)
prop_nm (char 50?)
prop_vl (text)
In the first table, plan on just keeping the absolute minimum # of fields you will need for about any system. (PKID, USERID, PSWRD, ACTV) may be enough.
Define your own prop_nm values and place all other user related details here, stored vertically. (Ideall you will have a 3rd table which has at least 2 columns and defines the prop_nm values you create.)
You will only ever need 2 queries and these should be encapsulated into a single ASP module, C# class or whatever. You will be able to add new properties whenever you want (there will be more, count on it.)
I use this tecnique for user definition and it has payed off many, many times. I don't recommend using this tecnique for just any data but for user login info, it is great.
Just my 2 cents.
|
|
|
|
|
Could I not store all account information inside a members table (access privileges, account expires, etc..) and only username and password inside auth_users. I'm thinking if I could then use an index on auth_users MemberID to quickly select the member information, this would be quite the optimization would it not?
i'm a total newbie with mySQL, so please forgive me if my terms are off.
]Thanks
"Two wrongs don't make a right, but three lefts do!" - Alex Barylski
|
|
|
|
|