New Record

E

entrodus

I know this must be an easy question to answer
but i cant seem to find out how to do it.

I am an experienced programmer in delphi but just started to learn
..NET.

What i am trying to do is:
1 - create a DataTable (Ok, done it)
2 - dynamic bind its columns with some textboxes in the form (Ok, done
it)
3 - set the DataTable in "Insert Mode" (How?!?!?)
4 - Have user to fill the values he wants and...
5 - Update the DataTable and save all the data in XML. (using WriteXML
i guess)


My problem is that i cant find a way to set the DataTable to insert
mode!!!
I dont really now if this logic applies to the DOT.NET framework.

The closest i got to my needs is to make a New DataRow and then add it
back to the DataTable. But since some of the columns are mandatory (not
null), i cant add it back, or set my own default values...

To put it in simple words... how do i initialize a DataTable in order
to have its values set without having to add a new DataRow...
 
E

entrodus

Cor, thank you for your immediate response.

The "Insert Mode" is not an official Microsoft term, Its just my way to
describe what i need to do. Let me clarify things up by an example


DataSet MyDS;
DataTable TblPeople;

private void btnCreateData_Click(object sender, EventArgs e)
{
MyDS = new DataSet();
MyDS.ReadXmlSchema("Test.xsd");

TblPeople = MyDS.Tables["PEOPLE"];
DataRow DrPeople = TblPeople.NewRow();

// I Dont want to initialize new values to the DataRow,
// but cannot do otherwise cause some of the fields are
mandatory (not null)
DrPeople["CODE"] = 667;
DrPeople["NAME"] = "The Doctor";

txtBind1.DataBindings.Add("TEXT", TblPeople, "CODE", true);
txtBind2.DataBindings.Add("TEXT", TblPeople, "NAME", true);

// By Removing this row, there is no default row to write
to,
// and data do not get automatically pushed to the
DataTable.
TblPeople.Rows.Add(DrPeople);
}

private void btnSave_Click(object sender, EventArgs e)
{
MyDS.WriteXml(@"c:\temp\People.xml");
}

-------------

In this example everything works like a charm.
User can alter Data and by pressing the Save button new data are being
saved to people.xml.

But this is no good enough for me, because i dont want to set initial
values to all the fields.

So... what am i missing here?

Is there another way to initialize the DataTable to accept data without
adding a new DataRow?


Entrodus.


Ο/Η Cor Ligthert [MVP] έγÏαψε:
 
C

Cor Ligthert [MVP]

Entrodus,

I think that in your code you can use the best the AddNew from the
currencymanager, that adds a row at the end of the table. The currency
position will set to that and therefore direct showed in your textboxes.

http://msdn2.microsoft.com/en-us/library/system.windows.forms.currencymanager.addnew.aspx

Always keep an eye that the right key is placed in the datarow, that gives
most often the problems.

I hope this helps,

Cor



"entrodus" <[email protected]> schreef in bericht
Cor, thank you for your immediate response.

The "Insert Mode" is not an official Microsoft term, Its just my way to
describe what i need to do. Let me clarify things up by an example


DataSet MyDS;
DataTable TblPeople;

private void btnCreateData_Click(object sender, EventArgs e)
{
MyDS = new DataSet();
MyDS.ReadXmlSchema("Test.xsd");

TblPeople = MyDS.Tables["PEOPLE"];
DataRow DrPeople = TblPeople.NewRow();

// I Dont want to initialize new values to the DataRow,
// but cannot do otherwise cause some of the fields are
mandatory (not null)
DrPeople["CODE"] = 667;
DrPeople["NAME"] = "The Doctor";

txtBind1.DataBindings.Add("TEXT", TblPeople, "CODE", true);
txtBind2.DataBindings.Add("TEXT", TblPeople, "NAME", true);

// By Removing this row, there is no default row to write
to,
// and data do not get automatically pushed to the
DataTable.
TblPeople.Rows.Add(DrPeople);
}

private void btnSave_Click(object sender, EventArgs e)
{
MyDS.WriteXml(@"c:\temp\People.xml");
}

-------------

In this example everything works like a charm.
User can alter Data and by pressing the Save button new data are being
saved to people.xml.

But this is no good enough for me, because i dont want to set initial
values to all the fields.

So... what am i missing here?

Is there another way to initialize the DataTable to accept data without
adding a new DataRow?


Entrodus.


?/? Cor Ligthert [MVP] ??????:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top