Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Why this code doesn't increment the number of Rows?
Message
General information
Forum:
ASP.NET
Category:
ADO.NET
Environment versions
Environment:
C# 3.0
OS:
Windows XP
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01399434
Message ID:
01399460
Views:
55
Thanks a lot, we already re-coded it (though quite not elegant for now). Save/Cancel now works OK.

>I don't know what's behind (int)ta.InsertOrderRecord(dr.OrderPk) method,
>but to be honest, I'm not fan of TableAdapter at all,
> I know it's really hard to change codes to get read of
>those TableAdapter(s). (Also I don't use wizards that
>use those objects in form to handle data manipulations,
>I'm not against it but I prefer to keep control of Data by
>code then I'll have enough power later on to do more.)
>
>To add a record in a DataTable, I use simple way,
>I think I'm not brave enough to use TableAdapter(s).
>
>I look at DataTable as a disconnected object that
>keeps my data and ADO.NET takes care of it.
>
>//DataTable myDT = new DataTable();
>// Add columns or get Table Schema from a DataBase Table from any DataBase Engine which stores your Data
>//...
>
>DataRow myDR = myDT.NewRow();
>myDR["dtClmn1"] = "Something";
>// Some logics to see if you can add your DataRow
>myDT.Rows.Add(myDR);
>
>I recomend TRY CATCH block always, it will keep you
>safe if your method fails cuz of any reason.
>
>int NewOrderID = 0;
>using( ... )
>{
> try
> {
> // do something
> NewOrderID = ...
> }
> catch( Expressin ex )
> {
> // do something
> NewOrderID = -1; // or Zero
> }
>}
>return NewOrderID;
>
>In this way you have a chance to check returned value
>to see if it worked or not.
>
>- Just I wanted to add, if you were looking for performace,
>instead of ColumnName, DataTableName, and such a kind of
>stuff, you can use index (ColumnIndex, DataTableIndex, ...),
>it will bring higher performance specially when you are dealing
>with huge number of records.
>
>- "return back the datatable?" No, you can pass your DataTable to a method and add a new row, then you'll have it in the DT
>- "Or may be I should pass it as a reference and insert.?" No, may be the problem is in "OrdersTableAdapter" in your InsertNewOrder method. If you pass your DataTable to a method, you can use DT.Rows.Add( myDR ) to add a row to it.
>
>I know this part of code is involved with other lines in the same class or even in other classes too,
>then I just tried to write my ideas.
>
>HTH
>
>> if (_dtOrder.Rows.Count == 0) //Add a new order
> > {
> > _drOrder = _dtOrder.NewOrdersRow();
>> _OrderBiz.InsertNewOrder(this._drOrder);
> > }
>>
>> don't change the _dtOrder.Rows.Count ? Should my _OrderBiz.InsertNewOrder method return back the datatable? Or may be I should pass it as a reference and insert.
>>
>> I'm guessing this is completely wrong implementation
>>
> > public int InsertNewOrder(OrdersDataSet.OrdersRow dr)
>> {
> > int NewOrderID;
>> using (OrdersTableAdapter ta = new OrdersTableAdapter())
> > {
> > dr.OrderPk = Guid.NewGuid();
>>
> > NewOrderID = (int)ta.InsertOrderRecord(dr.OrderPk);
> > }
>>
> > return NewOrderID;
> > }
>>
>> Since I don't know "which" table it now inserted record to and how can I update my reference in the form.
>>
>>Any ideas of how should I fix it?
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform