how to read record????

Posted by Subhadip under C# on 12/17/2010 | Points: 10 | Views : 1715 | Status : [Member] | Replies : 1
I HAVE INSERTED 5 RECORD OF STUDENT LIKE roll,name,address,age NOW IN WANT TO DISPLAY ALL THE FIVE RCECORD ON LABEL USING FIRST,LAST,NEXT,PREVIOUS BUTTON(for window application) how to write code?????

ID lblid NAME lblname
ADDRESS lbladdress




Responses

Posted by: T.saravanan on: 12/17/2010 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi Subhadip,

Why you choose to show a output in label ?Just try in gridview...

Any how...based on requirement try this way....
First to get a value from DB into DataTable..
Here dtData --> DataTable

Assign one integer variable in global

int n=0;


Get First Record...

string sText = string.Empty;
for(int nCol=0; nCol<dtData.Columns.Count; nCol++)
{
if(sText ! =string.Empty)
sText +="\r"; // If you want same row means sText += " ";
sText += dtData.Rows[0][nCol].ToString();
n = 0; // In this case user cannot allow to view the Previous record.
}


Get Next Record...

string sText = string.Empty;
for(int nCol=0; nCol<dtData.Columns.Count; nCol++)
{
if(sText ! =string.Empty)
sText +="\r"; // If you want same row means sText += " ";
sText += dtData.Rows[++n][nCol].ToString();
}


Get Previus Record...

string sText = string.Empty;
for(int nCol=0; nCol<dtData.Columns.Count; nCol++)
{
if(sText ! =string.Empty)
sText +="\r"; // If you want same row means sText += " ";
sText += dtData.Rows[--n][nCol].ToString();
}


Get Last Record...

string sText = string.Empty;
for(int nCol=0; nCol<dtData.Columns.Count; nCol++)
{
if(sText ! =string.Empty)
sText +="\r"; // If you want same row means sText += " ";
sText += dtData.Rows[dtData.Rows.Count-1][nCol].ToString();
n=dtData.Rows.Count-1; // In this case user cannot allow to view the next record.
}


After looping set string value into your label
Label1.Text = sText;


Cheers :)


Thanks,
T.Saravanan

Subhadip, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response