Showing posts with label row. Show all posts
Showing posts with label row. Show all posts

Thursday, March 29, 2012

Please Explain

Hi All

Can anyone help me in understanding the highlighted text please.

For Each row As DataRow In ds.Tables(0).Rows
Dim arr() As Object = row.ItemArray()
For i As Integer = 0 To arr.Length - 1


If arr(i).ToString().IndexOf(",") > 0 Then ' I m unable to get this line of code.


record = record & Chr(34) & arr(i).ToString() & Chr(34) & ","
Else
record = record & arr(i).ToString() & ","
End If
Next
body = body & record.Substring(0, record.Length - 1) & vbCrLf
record = ""
Next

Thanks

Asif Ali.

take the object in Array arr at position indicated by i

convert to a string

find the index (position) of a comma character

see if the comma occurred after the first character position


Hi there

Fantastic explanation..

Thanks Again

Asif.

Saturday, March 24, 2012

Please help how to get the count of rows in Datasets data

I want to get the row count.
I am doing the following to see are there any records in the dataset with the same ID, But i am in the edit mode, obviously there will be one so i want to check are there two rows with same strAccessID.

Please help how i can get the count after doing the find.

Thank you very much.

<code>
Dim Row As DataRow
myDataSet.Tables(0).PrimaryKey = New DataColumn() {myDataSet.Tables(0).Columns("AccessID")}
Row = myDataSet.Tables(0).Rows.Find(CInt(strAccessID))


If Not Row Is Nothing Then
SimpleMessageBox("You cannot have more than one record with same ID.")
Exit Sub
End If

</code>

DataTable.Rows.Find will only find a specific row in a collection of DataRow objects, so you may need to useDataTable.Select Method.


If the data to the dataset is comming from the database you can checkthat "Duplicate" data is never entered in the first place.


Its a C# code but u can see the concept and can see its alternate in VB.NET

If u want to retreive the coutn of rows in the dataset then u can use

dset.Tables[0].Rows.Count

dset is ur dataset this will give u the count of rows that are in dataset.And u can loop less thandset.Tables[0].Rows.Countand chechk that whether the key already exists or not.

It will work,Feel free to ask more...


How can i check a specific column only in the datasets data this column is a unique column so i dont want to have no two records in the datasets data with the same straccessid, if there are any records with this value strAccessID.

dset.Tables[0].Rows.Count

Another thing i use the dataset on the front end with the xml file means each time i fill the data in the dataset is not from the Database, only the first time i get the data from database and fill to dataset and also write the data to xml file now, i play with the data on the front end in the disconnected mode. and finally when everything is done then i upload all my xml files data using sqlxmlbulkload to database table.

Please let me know, Thank you very much.

Friday, March 16, 2012

Please help me understand this PostBack Issue

I am inserting a row in a database. All that works fine. What I now
need is the last inserted id from the database. I can get that. Again
all working.
Then what I need to have is that same last inserted id key to be
available when the page reloads. When I press the button to insert the
data, I can do this:
Session("last")=LAST_ID;
Response.Write("My row id is: " + Session("last"));
//this works and is inside my INSERT button_click event
But when the Page_Load comes back I cannot see it. I try this:
if (Page.IsPostBack)
Response.Write("My row upon postback is: " + Session("last"));
//this fails upon postback in the Page_Load
It is just blank. Nothing there.
Instead of a Session variable, I have tried a static variable, (I think
ViewState, but am not sure), a global variable, nothing holds the data
upon PostBack.
Thank you for any help.And what I don't get is that when I do a trace it shows my INSERT code
in the Begin PostBack which looks like I would have access to the
variable.
I'm sorry to keep responding to myself, but it looks like the lifecycle
is as follows:
Page_Load
Button_click
So,
Page_Load fails to show a Session Variable or any other because it has
not been initialized yet.
Button_click is where the row is inserted and the last ID is given.
But because the Button_click has fired after the Page_load the
page_load never sees the value.
So I must find a way to get the last row id..oh wait..I populate the
controls after the insert in that click event instead of the Page_Load
event.
Thanks!
Umm, glad to be of assistance? :)
Mythran
needin4mation@.gmail.com wrote:

> I'm sorry to keep responding to myself, but it looks like the
> lifecycle is as follows:
> Page_Load
> Button_click
RTM...
http://msdn.microsoft.com/library/d...y/en-us/cpguide
/html/cpconControlExecutionLifecycle.asp
;-)
http://www.joergjooss.de
mailto:news-reply@.joergjooss.de

Please help me understand this PostBack Issue

I am inserting a row in a database. All that works fine. What I now
need is the last inserted id from the database. I can get that. Again
all working.

Then what I need to have is that same last inserted id key to be
available when the page reloads. When I press the button to insert the
data, I can do this:

Session("last")=LAST_ID;
Response.Write("My row id is: " + Session("last"));
//this works and is inside my INSERT button_click event

But when the Page_Load comes back I cannot see it. I try this:

if (Page.IsPostBack)
Response.Write("My row upon postback is: " + Session("last"));
//this fails upon postback in the Page_Load

It is just blank. Nothing there.

Instead of a Session variable, I have tried a static variable, (I think
ViewState, but am not sure), a global variable, nothing holds the data
upon PostBack.

Thank you for any help.And what I don't get is that when I do a trace it shows my INSERT code
in the Begin PostBack which looks like I would have access to the
variable.
I'm sorry to keep responding to myself, but it looks like the lifecycle
is as follows:

Page_Load
Button_click

So,

Page_Load fails to show a Session Variable or any other because it has
not been initialized yet.
Button_click is where the row is inserted and the last ID is given.

But because the Button_click has fired after the Page_load the
page_load never sees the value.

So I must find a way to get the last row id..oh wait..I populate the
controls after the insert in that click event instead of the Page_Load
event.

Thanks!
Umm, glad to be of assistance? :)

Mythran
needin4mation@.gmail.com wrote:

> I'm sorry to keep responding to myself, but it looks like the
> lifecycle is as follows:
> Page_Load
> Button_click

RTM...

http://msdn.microsoft.com/library/d...y/en-us/cpguide
/html/cpconControlExecutionLifecycle.asp

;-)

--
http://www.joergjooss.de
mailto:news-reply@.joergjooss.de