|
Thanks for u to be interested to help me to correct code to work well but i say when i post the question " if i make all table in one class it work" and what motivate me to find solution and make each classes are separated is that when i make all attributes in one class this make problem if i want to display the data of any table only without display other so if i do this when i add object, the other attributes which i skip from class give default values to skipped values by zero so this force me to make one class for the state of joining when i want to display record that have a relation with other table and make one when i want to display the data of one table. ,thanks again for u and may Allah bless u for u effort.
|
|
|
|
|
Basically there is nothing wrong if you keep the data in two separate classes like in the first post. The problem is mainly in DataGrid.
Perhaps you could use more powerful DataGridView instead. With that control you could create a combo box column for category so you wouldn't have problems with empty foreign key properties. This way you could have a combobox for user to select what category he wants to use for a person and if category is selected, it will be shown.
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
I Make some changes in code and data displayed but not displayed in normal form but each data in column displayed in row and no header text to columns.and the question also if i make another method to update data , my work is to do changes in destination array and compare the id that hold in array with the record in db and apply changes or wat?
public ArrayList RetriveStdentInfo()
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = myCon;
cmd.CommandText = "dbo.StoredProcedure2";
cmd.CommandType = CommandType.StoredProcedure;
myCon.Open();
IDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
ArrayList seqCat = new ArrayList();
ArrayList seqStudent = new ArrayList();
<code>ArrayList destnation = new ArrayList();</code>
int prevCatId = 0;
while (reader.Read())
{
MyStudent std = new MyStudent();
std.Stid = reader.GetInt32(0);
std.Sname = reader.GetString(reader.GetOrdinal("stname"));
std.Catgid = reader.GetInt32(reader.GetOrdinal("Catgid"));
if (prevCatId != reader.GetInt32(reader.GetOrdinal("Catgid")))
{
CatgBL cat = new CatgBL();
cat.CatgName = reader.GetString(reader.GetOrdinal("CatgName"));
seqCat.Add(cat);
prevCatId = reader.GetInt32(reader.GetOrdinal("Catgid"));
}
seqStudent.Add(std);
}
<code> foreach ( MyStudent var in seqStudent)
{
destnation.Add((int)var.Catgid);
destnation.Add((string)var.Sname);
destnation.Add((int)var.Stid);
}
foreach (CatgBL var in seqCat)
{
destnation.Add((int)var.Cid);
destnation.Add((string)var.CatgName);
}
return destnation;</code>
}
|
|
|
|
|
|
you can use constraint on C# code to joid two tables
|
|
|
|
|
but why ? and what is the benefit if i do ?
|
|
|
|
|
can you explain your problems
|
|
|
|
|
go to the Subject , i explain the problem and code also.
|
|
|
|
|
I have got a table say something like this:
ID VARCHAR(30),
ParentID VARCHAR(30),
TITLE NVARCHAR(100)
As it seems, this table has a parent-child relation with itself. the ID column is not auto-generated and is a combination of ASCII characters and numbers with length of 30.
Now, I want to move all the data contained in the above table to the following table:
ID SMALLINT
ParentID INT
TITLE NVARCHAR(100)
In this table, ID is an auto-generated integer Identity column starting from 1.
What is the best way for converting the ID columns while moving them to the new table?
Thanks in advance for any help
|
|
|
|
|
I think you have to do this in two parts. If you have a natural key on the table, it's easiest to use that. Something like (just a draft, may contain several mistakes):
INSERT INTO TargetTable (Title)
SELECT Title
FROM SourceTable
--
UPDATE TargetTable
SET ParentID = (SELECT tt1.Id
FROM TargetTable tt1, SourceTable st1, SourceTable st2
WHERE targettable.Title = st1.Title
AND st2.Id = st1.ParentId
AND st2.Title = tt1.Title)
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
Thank you, seems a very good idea. I will try it
|
|
|
|
|
You're welcome
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
Shouldn't ID and ParentID have the same type? Are the Titles unique?
|
|
|
|
|
ID and ParentID are of the same type (both varchar in source table and INT in destination table)
Titles may not necessarily be unique. Therefor, I might have a title like 'business' whose parentId is NULL and have another title like 'business' whose parentId is 'POVAD78Y6CSDD8F76NEL876D'.
The grand parent of all items is an item whose parentId is NULL (a root element).
Could you suggest a good solution please?
|
|
|
|
|
Maysam Mahfouzi wrote: INT in destination table
That's not what this says:
ID SMALLINT
ParentID INT
Maysam Mahfouzi wrote: Titles may not necessarily be unique
That would seem to eliminate the other suggestion.
Maysam Mahfouzi wrote: Could you suggest a good solution please?
Maybe...
Perhaps you could add the existing varchar columns to the new table temporarily, copy the data over, then set the ParentID values based on the old mappings within the new table, and then remove the varchar IDs.
|
|
|
|
|
PIEBALDconsult wrote: That's not what this says:
ID SMALLINT
ParentID INT
I'm sorry think of those both as SMALLINT.
PIEBALDconsult wrote: That would seem to eliminate the other suggestion.
You are right, at that time I didn't know titles are not unique. I just found some duplicate titles.
I can't rely on old VARCHAR values to calculate new ID and ParentIDs in SMALLINT. How is it possible to move a string like 'LSFDKJSDLFKSJDLJSLDK' to a SMALLINT column?
|
|
|
|
|
Maysam Mahfouzi wrote: I can't rely on old VARCHAR values to calculate new ID
No, you're using auto-increment for the new IDs, right?
ID,ParentId,OldID,OldParentId,Description (or whatever it is)
INSERT INTO NewTable (OldID,OldParentId,Description) SELECT * FROM OldTable (add an ORDER BY clause if desired)
And you get all new IDs. You also have the original mappings. For any row with non-null OldParentId, match it to the row with that OldID to get the (new) ID to put in the (new) ParentID.
Something like this:
UPDATE NewTable
SET ParentId=B.ID
FROM NewTable A
INNER JOIN NewTable B
ON A.OldParentID=B.OldID
(I think I'll go test that now.)
Then remove the OldID and OldParentID columns (if desired).
|
|
|
|
|
So I think I've got to add OldID and OldParentID columns to the destination table, move data the way you've suggested and then remove OldID and OldParentID columns. This solution seems quite perfect and beautiful and I'm going to test it as soon as I have access to database. I'm also thinking of a way to move data without using those two temporary columns in target table.
I really really appreciate your help and time PIEBALDconsult
_
|
|
|
|
|
Just got around to testing it:
INSERT INTO NewTable (OldID,OldParentID,Description) SELECT * FROM OldTable
SELECT * FROM NewTable
UPDATE A
SET ParentID=B.ID
FROM NewTable A
INNER JOIN NewTable B
ON A.OldParentID=B.OldID
SELECT * FROM NewTable
It worked on the small amount of data I created to test it:
1 NULL 1 NULL Section 1
2 NULL 2 NULL Section 2
3 1 1.a 1 Section 1.a
4 1 1.b 1 Section 1.b
5 2 2.a 2 Section 2.a
6 2 2.b 2 Section 2.b
7 3 1.a.i 1.a Section 1.a.i
8 3 1.a.ii 1.a Section 1.a.ii
|
|
|
|
|
Thank you again, I tested it and it worked for me too
|
|
|
|
|
hai all
i am using sql server 2000.
when i worked in .net,suddenly sql server service manager is stopped.then i tried to start the sql server service manager in service...it showing error as "The MS SQLSERVER service on local computer started and then stopped.some services stop automatically if they have no work to do,for example,the performance logs and alerts service."how to solve this?
thanks in advance.
|
|
|
|
|
Anything in Event log (system or application).
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
i can't understand...what u say....
|
|
|
|
|
If the service stops unexpectedly, open Event Viewer from control panel and check both Application log and System log. Find out if there are any error messages related to Service Manager.
Or do you mean the windows application which is found in Task bar and can be started from Start menu?
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
Is there an easy way to restrict values - returned by a SQL select - to certain boundaries?
I've got a some tables like this
dataTBL:
dt id x
2008-01-01 10:00 1 5.13
2008-01-01 10:00 2 14.00
2008-01-01 10:00 3 -2.10
2008-01-01 10:00 4 1.65
2008-01-01 11:00 1 5.19
...
compTBL (balancing computation rules):
resultID baseID k d minX maxX
100 1 +1.0 0 null null
100 2 -0.5 0 +3 null
100 3 -0.5 +5 -10 0
200 1 +1.0 0 null null
200 4 -1.0 10 0 100
...
And I want to calculate for ID 100 e.g. the values
5.13 * 1.0 + 0.0 (no limits)
+ 14.00 *-0.5 + 0.0 (but at least 3)
+ -2.10 *-0.5 + 5.0 (but at least -10 and maximal 0)
I'm working with Sql Server 2005 and at the moment I'm doing it this way
select
dt,
resultID,
sum(
case
when isnull(x,0) * k + d < minX then minX
when isnull(x,0) * k + d > maxX then maxX
else isnull(x,0) * k + d
end
)
from dataTBL join compTBL on dataID = baseID
group by dt, resultID
This works fine, but I don't like having the same expression three times just for testing <, > and else.
Is there no shorter way to write this case-expression? Or ist there some other function I could use? Is there something like "r = MaximumOf(MinimumOf(x,maxX),minX)" - or even better "r = ClipToBoundaries(x,minX,maxX)"?
Thanks
Andy
|
|
|
|