|
Supratik De wrote:
DataTable parentTable = new DataTable("Parents");
parentTable.Columns.Add("ParentCategoryId", typeof(int));
...
DataRelation parentChildRelation = new DataRelation("ParentChild", parentTable.Columns["CategoryId"], childTable.Columns["ParentCategoryId"]);
...
I am getting a ArgumentNullException on DataRelation line. The error is "'column' argument cannot be null.
parentTable doesn't contain a column called CategoryId , because the line which adds that column has been commented out.
From the description, it sounds like you only want a sinlge DataTable , with a self-referencing relationship.
You'll need to tell the DataRelation not to try to create constraints, since there is no row with a CategoryId of "-1". Alternatively, replace the "-1" in the ParentCategoryId column with null .
You can use the GetParentRow method[^] to get the parent row, and the GetChildRows method[^] to get the child rows.
If you set the table's PrimaryKey , you can use the Rows.Find method[^] to quickly find a row by its CategoryId.
This should get you started:
DataTable theTable = new DataTable("Data");
theTable.Columns.Add("CategoryId", typeof(int));
theTable.Columns.Add("ParentCategoryId", typeof(int));
theTable.Columns.Add("Name", typeof(string));
theTable.Columns.Add("Keywords", typeof(string));
theTable.PrimaryKey = new DataColumn[] { theTable.Columns[0] };
theTable.Rows.Add(new object[] { 100, -1, "Business", "Money" });
theTable.Rows.Add(new object[] { 200, -1, "Tutoring", "Teaching" });
theTable.Rows.Add(new object[] { 101, 100, "Accounting", "Taxes" });
theTable.Rows.Add(new object[] { 102, 100, "Taxation", null });
theTable.Rows.Add(new object[] { 201, 200, "Computer", null });
theTable.Rows.Add(new object[] { 103, 101, "Corporate Tax", null });
theTable.Rows.Add(new object[] { 202, 201, "Operating System", null });
theTable.Rows.Add(new object[] { 109, 101, "Small Business Tax", null });
ds.Tables.Add(theTable);
DataRelation parentCategoryRelation = new DataRelation("ParentCategory",
theTable.Columns["CategoryId"],
theTable.Columns["ParentCategoryId"],
false);
ds.Relations.Add(parentCategoryRelation);
DataRow theRow = theTable.Rows.Find(201);
DataRow parentRow = theRow.GetParentRow(parentCategoryRelation);
DataRow[] childRows = theRow.GetChildRows(parentCategoryRelation);
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
This is a continuation, in a way, of a recent thread I started here, and I would like to remind you, gentle reader, that this forum was (once) the C# language discussion forum.
If this (and the code) provoke any interesting discussion of how you choose to implement Interfaces ... keeping in mind the several roles Interfaces can play (contract, interchange-object with restricted scope, etc.), I'll be ... all ears
The code shown here demonstrates four "styles" of interface implementation: in each case a Class with a Dictionary is being created, and the access to that Dictionary is restricted; the only thing "exposed" of the Dictionary are methods to add, and remove, key/value pairs.
1. focus on "object:" explicit implementation of Dictionary (thanks to Richard Deeming for reminding me to consider explicit implementation).
2. focus on "behavior:" implicit implementation of methods (as suggested by Sascha LeFavre and Pete O'Hanlon).
3. using separate interfaces to "separate" exposed object(s) from exposed method(s): probably not a good example, what interests me is the issue of when one might "break-out" Interfaces.
4. using a Custom Generic Class that inherits from Dictionary in an Interface. Meant to be an "extreme" example.
using System;
using System.Collections.Generic;
namespace InterfaceImplementations
{
public interface IRequire1
{
Dictionary<string, int> RequiredDictionary { get; }
}
public class Example1 : IRequire1
{
private Dictionary<string, int> internalDictionary { set; get; }
Dictionary<string, int> IRequire1.RequiredDictionary
{
get { return this.internalDictionary; }
}
public Example1()
{
internalDictionary = new Dictionary<string, int>();
}
public void AddEntry(string str, int i)
{
internalDictionary.Add(str, i);
}
public void RemoveEntry(string key)
{
internalDictionary.Remove(key);
}
}
public interface IRequire2
{
void AddEntry(string key, int value );
void RemoveEntry(string key);
}
public class Example2 : IRequire2
{
private Dictionary<string, int> internalDictionary { set; get; }
public Example2()
{
internalDictionary = new Dictionary<string, int>();
}
public void AddEntry(string key, int value)
{
internalDictionary.Add(key, value);
}
public void RemoveEntry(string key)
{
internalDictionary.Remove(key);
}
}
public interface IRequire3Dictionary
{
Dictionary<string, int> RequiredDictionary { get; }
}
public interface IRequire3Methods
{
void AddEntry(string key, int value);
void RemoveEntry(string key);
}
public class Example3 : IRequire3Dictionary, IRequire3Methods
{
private Dictionary<string, int> internalDictionary { set; get; }
public Example3()
{
internalDictionary = new Dictionary<string, int>();
}
Dictionary<string, int> IRequire3Dictionary.RequiredDictionary
{
get { return this.internalDictionary; }
}
public void AddEntry(string key, int value)
{
internalDictionary.Add(key, value);
}
public void RemoveEntry(string key)
{
internalDictionary.Remove(key);
}
}
public interface IRequire4<T1,T2>
{
CustomDictionary<T1, T2> CustomDictionary { get; }
}
public class CustomDictionary<T1, T2> : Dictionary<T1, T2>
{
public void AddEntry(T1 key, T2 value)
{
base.Add(key, value);
}
public void RemoveEntry(T1 key)
{
base.Remove(key);
}
}
public class Example4 : IRequire4<string, int>
{
private CustomDictionary<string, int> internalDictionary { set; get; }
CustomDictionary<string, int> IRequire4<string, int>.CustomDictionary
{
get { return internalDictionary; }
}
public Example4()
{
internalDictionary = new CustomDictionary<string, int>();
}
public void AddEntry(string key, int value)
{
internalDictionary.Add(key, value);
}
public void RemoveEntry(string key)
{
internalDictionary.Remove(key);
}
}
} And, yes, I do test code I post:
Example1 example1 = new Example1();
example1.AddEntry("hello", 100);
Example2 example2 = new Example2();
example2.AddEntry("goodbye", 200);
Example3 example3 = new Example3();
example3.AddEntry("ex 4", 999);
Example4 example4 = new Example4();
example4.AddEntry("ex 4", 2222);
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
modified 25-May-15 10:14am.
|
|
|
|
|
I'd go with #2 - the fact that the class is using a Dictionary<TKey, TValue> to store the values is an implementation detail, which seems to be irrelevant to the consumer of the interface. All the consumer cares about is that your class has the AddEntry(string, int) and RemoveEntry(string) methods, so that's all that the interface should expose.
Depending on the intended use, it might be worth making the interface generic:
public interface IRequire<TKey, TValue>
{
void AddEntry(TKey key, TValue value);
void RemoveEntry(TKey key);
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi There,
I was wondering if someone might have any information as to why when I place a toolstrip in a windows form I get a sort of grey border on the right hand side. Its not that noticeable but it is visible and I'm intrigued why it may be there.
http://i.imgur.com/pBrUByR.png[^]
I have included an image of what I am trying to explain, you may need to zoom in a bit on the image to see it.
|
|
|
|
|
I've noticed it too. Try increasing the R-margin of the Toolstrip and see if that pushes the grey border out of view.
/ravi
|
|
|
|
|
Hello again... today i'm asking about the report how to do report from date to date i'm using asp.net and c# i have tried many tutorials but i failed so any one can help??.. Thanks
|
|
|
|
|
What have you tried?
Where are you stuck?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
i tried many ways but most of the tutorials for vb not asp so i want example or tutorials please help ??
|
|
|
|
|
First work out what you are going to use as a reporting tool!
Then work out how you are going store and return the data (presumably a database)
Then work out how you are going to extract the data for the report (query, collection, stored procedure)
Then write the report in your desired reporting tool to display the data you have extracted.
Then write an app that will display the report for the user.
Simple see.
How can we possibly recommend a tutorial when we know only that you are using asp.net.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
i have make a database and aspx page and i used report viewer tool and i works but now i would like to generate a report from date to date i saw many ways using crystal report so crystal report is the way i should used to get date to date report??
|
|
|
|
|
No crystal reports is the worst choice you could make, use almost any other reporting tool and you will be in front. I recommend SQL server reporting services, comes with the database.
You need to use the database query to get date specific records. The reporting tool does not do that for you.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
thanks for ur replay and i understand u but what i miss is how to do it could u please make an example or to recommend any tutorial for me please??
|
|
|
|
|
Search google for a tutorial as JSchell suggested.
Select FieldList...
From SomeTable
Where datefield between @FromDate and @ToDate
That is a query to get data for a report, assuming you are using SQL Server! You have not even to;d us the database you are using, nor the reporting tool you have chosen.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Following in google gives examples of reports
C# example report
|
|
|
|
|
Incorrect syntax near the keyword 'update'. cmd1.CommandText = "select update"
|
|
|
|
|
"select update" is not a valid SQL-statement. You should look for some SQL-tutorial[^].
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
|
Hi,
I wanted to know how can I encrypt any number to a 6 unique alphanumeric digits using C#?
Thanks
Jassim[^]
Technology News @ www.JassimRahma.com
|
|
|
|
|
ANY number? Down to a UNIQUE 6 digit code?
Think about that. How are you going to represent any number UNIQUELY in a space that, by definition, can only hold 1,000,000 unique values?
By the way, that's not encryption. That's a hash.
You might want to go into what you're really trying to do with this.
|
|
|
|
|
Though Dave overlooked that you were talking about an alphanumeric representation, this doesn't change the fact that you can't represent any number in 6 digits UNIQUE alphanumeric.
1.) 2'175'005'370 would be the highest number you can represent that way ("ZYXWVU").
2.) Because the digits should be unique, not all numbers in that range can be represented. The lowest number that can be represented is 1'776'965 (= "012345") and there will be several "gaps" in between.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
modified 22-May-15 21:25pm.
|
|
|
|
|
Just to add to what the others say: Encryption implies that Decryption is possible - but what you are talking about is Basically Hashing (as Dave mentioned) which cannot be reversed, cannot be "de-hashed". Once you have generated your unique code, you can't get the original input back. Encryption does not have a fixed length output, only hashing does.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
modified 23-May-15 6:23am.
|
|
|
|
|
Getting an error: input string was not in a correct format
asp:
onrowdatabound="highlightrow"
protected void highlightrow(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int ActualFTE=Convert.ToInt32(e.Row.Cells[5].Text);
if (ActualFTE > 1.25)
{
e.Row.BackColor = Color.Red;
}
}
}
modified 22-May-15 14:31pm.
|
|
|
|
|
The error message says it clearly.
You are trying to covert a decimal to int.
Change your stament like below and try.
decimal ActualFTE=Convert.ToDecimal(e.Row.Cells[5].Text);
if (ActualFTE > 1.25)
|
|
|
|
|
|
Still getting the same error.
|
|
|
|
|