|
Hi,
assuming each of the tables where you want to insert data has columns with the same names as the columns in the source table you could do something like this:
foreach (DataRow theRow in dataClasses)
{
string className = theRow["Class_Name"].ToString();
DataTable tableToInsertInto = theSaveModelDataSet.Tables["New" + className];
if (tempDataSet.Tables[0].Rows.Count != 0)
{
foreach (DataRow row in tempDataSet.Tables[0].Rows)
{
DataRow rowToInsert = tableToInsertInto.NewRow();
foreach (DataColumn column in tempDataSet.Tables[0].Column) {
if (tableToInsertInto.Columns.Contains(column.ColumnName)) {
rowToInsert[column.ColumnName] = row[column.ColumnName];
}
}
tableToInsertInto.Rows.Add(rowToInsert);
}
}
}
Robert
|
|
|
|
|
Thank you, it works wonderfully.
The next question is, how do i do the same, but instead of selecting from a dataset, i get the information from a datarow[]
<br />
DataRow[] newUserServiceRows = graphShared.MainDataSet.Tables["NodeChanges"].Select("stateChanged = " + (int)ServiceModeler.ModelerClass.StateChangeType.Added + " AND className = '" + className + "' AND userCreated = 'y'");<br />
<br />
foreach (DataRow theRow1 in newUserServiceRows)<br />
{<br />
string CMDB_Version = theRow1["Node_Version"].ToString();<br />
string Service = theRow1["Node_Key"].ToString();<br />
string Label = theRow1["Node_Key"].ToString();<br />
string Managed = "";<br />
string Live = "";<br />
string URL = "";<br />
string Classification = "";<br />
string Grouping = "";<br />
string Profile_Name = "";<br />
<br />
nodeSets[0] = CMDB_Version;<br />
nodeSets[1] = Service;<br />
nodeSets[2] = Label;<br />
nodeSets[3] = Managed;<br />
nodeSets[4] = Live;<br />
nodeSets[5] = URL;<br />
nodeSets[6] = Classification;<br />
nodeSets[7] = Grouping;<br />
nodeSets[8] = Profile_Name;<br />
<br />
theSaveModelDataSet.Tables["New" + className].Rows.Add(nodeSets);<br />
}<br />
Regards,
Gareth.
|
|
|
|
|
Hi,
that's nearly the same:
DataTable tableNodeChanges = graphShared.MainDataSet.Tables["NodeChanges"];
DataRow[] newUserServiceRows = tableNodeChanges.Select("stateChanged = " +
(int)ServiceModeler.ModelerClass.StateChangeType.Added +
" AND className = '" + className +
"' AND userCreated = 'y'");
DataTable tableToInsertInto = theSaveModelDataSet.Tables["New" + className];
foreach (DataRow row in newUserServiceRows)
{
DataRow rowToInsert = tableToInsertInto.NewRow();
foreach (DataColumn column in tableNodeChanges.Column) {
if (tableToInsertInto.Columns.Contains(column.ColumnName)) {
rowToInsert[column.ColumnName] = row[column.ColumnName];
}
}
tableToInsertInto.Rows.Add(rowToInsert);
}
Robert
|
|
|
|
|
Robert, the problem with the code you suggested is that the datatable im getting the data from isnt the same as the datatable im inserting into, thus the columns.contains will never match.
|
|
|
|
|
Well then you will have to do some more manual work:
DataRow[] newUserServiceRows = graphShared.MainDataSet.Tables["NodeChanges"].Select("stateChanged = " + (int)ServiceModeler.ModelerClass.StateChangeType.Added + " AND className = '" + className + "' AND userCreated = 'y'");
foreach (DataRow theRow1 in newUserServiceRows)
{
object[] nodeSets1 = new object[] {
theRow1["Node_Version"].ToString(), theRow1["Node_Key"].ToString(),
theRow1["Node_Key"].ToString(), "", "", "", "", "", "" };
theSaveModelDataSet.Tables["New" + className1].Rows.Add(nodeSets1);
object[] nodeSets2 = new object[] {
"", "",theRow1["Node_Key"].ToString(), theRow1["Node_XXX"].ToString()
theRow1["Node_YYY"].ToString(), "", "", "", "", "", "" };
theSaveModelDataSet.Tables["New" + className2].Rows.Add(nodeSets2);
object[] nodeSets3 = new object[] {
theRow1["Node_Key"].ToString(), theRow1["Node_Key"].ToString(),
"", "", "", "", "", theRow1["Node_Key"], "" };
theSaveModelDataSet.Tables["New" + className3].Rows.Add(nodeSets3);
}
This generally hardcodes how the object arrays for each destination table have to be generated. I just invented some combination. Thus you wil have to make it correct yourself.
Robert
|
|
|
|
|
Hi,
Is method hiding polymorphism?
_____________________________
Success is not something to wait for, its something to work for.
|
|
|
|
|
No
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
It can be and it can be not. It all depends upon situation.
sAqIb
"Our scientific power has outrun our spiritual power. We have guided missiles and misguided men."
Dr. Martin Luther King Jr.
|
|
|
|
|
Polymorphism is when derived classes do different things by overriding base methods. Hiding members does not fit that definition.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
but in actualy they are hiding the actual definition of the methods of base classes.
sAqIb
"Our scientific power has outrun our spiritual power. We have guided missiles and misguided men."
Dr. Martin Luther King Jr.
|
|
|
|
|
Oh, sure - they are replacing them.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Christian Graus wrote: they are replacing them
i agree with you Christian Graus.
what i understand is that c# suggest member hiding through the new keyword, means, a new member is defined in the derived class. while polymorphism is achived through overriding (which is not hiding).
_____________________________
Success is not something to wait for, its something to work for.
|
|
|
|
|
I have a base form and couple of derived forms.
I want to override Hide method of the base form. But the problem here is we have no facility to override hide method. How do I go about it?
Thanks in advance.
|
|
|
|
|
Hello,
I think you could use this for your base Forms class:
<br />
public new virtual void Hide()<br />
{<br />
base.Hide();<br />
}<br />
And this for your derived classes:
<br />
public override void Hide()<br />
{<br />
base.Hide();<br />
}<br />
Hope that helps you.
All the best,
Martin
|
|
|
|
|
Thanks Martin
I'll Try and let you know
|
|
|
|
|
Hi all,
I had a Console Application which name is myConsoleApp and now I want to run that Console Application from Windows App. How must I do?. For example:
The way to run my Console Application is:
myConsoleApp args1 args2
that purpose is convert args1 to args2 then save args2 to disk . Now I have a Windows Application with two Textboxes, The first Textbox's name is txtSource, the second Textbox's name is txtDest. I want to run my above Console Application with args1's value is txtSource.Text, args2's value is txtDest.Text. When I press Convert button then the conversion is process.
My application is convert two file.
Please help me!
Best regard!
Thanks!
|
|
|
|
|
Process.Start allows you to pass parameters.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hi,
I have a question. Is there any .Net class or method to set or get metadata (Like Autor, Title, Description etc...) information of file (.png, .jpeg files) using C#?
Any idea?
Thanks!
best regard
Adiphe
"...all is simple, but there is always simpler ..."
|
|
|
|
|
Yes, there are classes around that do this. The fotovision sample contains some examples, in VB.NET.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Thanks Christian!
where can i find the fotovision sample please?
best regard
Adiphe
"...all is simple, but there is always simpler ..."
|
|
|
|
|
|
Hi to all!
A short question:
Is it possible, to use an object,list,array or something like that as a database?
So I want to run SQL like queries on my object.
Ex.
I have a list, witch contains Person object (List<person> Persons)
Person class for ex.:
<br />
class Person<br />
{<br />
private int _id;<br />
public int ID<br />
{<br />
get{return _id}<br />
}<br />
private string _name;<br />
public string Name<br />
{<br />
get{return _name}<br />
}<br />
}<br />
I want to run a select for those persons who have id under 10 like this: SELECT * FROM Persons WHERE ID<10
How can I do this?
I try it witd bindingsource, try to add my class as project datasource, but nothing work
Thanks for help.
|
|
|
|
|
|
Thank's for quick replay.
I do this way, some times ago, but now, I wont write all the search, and filter method by hand.
Becouse of the complex querys, witch generated at runtime, as the user wants.
Ex.:
somethimes I ned a quer like this:
select * from partners where id<10 and name like'Mr.%' .....
and somethimes need group by option too.
|
|
|
|
|
Dear all,
I used below lines to achieve some results from the Sql Server 2000 database.
My question is why there are always 2 Process ID created for one "adapter.Fill()" method even the connection is disposed.
The Process ID created will disappear after the application exits.
Thanks for your attension.
System.Data.DataTable tb = new System.Data.DataTable();
SqlDataAdapter adapter = new SqlDataAdapter();
SqlConnection conn = new SqlConnection(connectionstring);
adapter.SelectCommand = new SqlCommand( "brm_sel_rackstatus", conn);
adapter.SelectCommand.CommandType = CommandType.StoredProcedure;
adapter.SelectCommand.Parameters.Add("@rack",SqlDbType.Int,32);
adapter.SelectCommand.Parameters.Add("@startcol",SqlDbType.Int,32);
adapter.SelectCommand.Parameters.Add("@endcol",SqlDbType.Int,32);
adapter.SelectCommand.Parameters[0].Value = this.rack;
adapter.SelectCommand.Parameters[1].Value = this.startcol;
adapter.SelectCommand.Parameters[2].Value = this.endcol;
adapter.Fill(tb);
adapter.Dispose();
conn.Dispose();
coby
|
|
|
|