how find recored from the database

Answer Posted / venky

Dear friend my answer is relating to csharp.net....SQLSERVER Database.

TO get records from database

1) our Application have to Connect with database.

SQlconnection cn=new sqlconnectio(@"server=.\SQLEXPRESS;Database=mydatabase;Integrated Security=SSPI");
cn.open();

2) we have to prepare COMMAND object Which encapsulate a sql statement and connection obj.


SQLCommand cmd=new Sqlcommand("select * from table1",cn);

then we call following method to get records

SqlDataReader rdr= cmd.ExecuteReader(CommandBehavior.CloseConnection);
int f_cnt= rdr.FieldCount;
Type t= rdr.GetFieldType(1);

while(rdr.Read())
{
int cou = rdr.FieldCount;
for(int i1=0;i1<cou;i1++)
{


string s2 = rdr.GetValue(i1).ToString();
ans = ans + " " + s2+" ";


}
i++;
ans = ans + "\n";

}
MessageBox.Show(ans);

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are window applications?

506


To which namespace does the control class belong?

534


Which property is used to specify the use of an element in the user interface and reports it to the accessibility aids?

559


Is form action required?

515


What is the full form of gac?

650






Explain how barcode create in the report?

574


Name the property which is used to specify the source from where the crystal reports would be accessed.

557


Is windows an application software?

523


What is dynamic linking?

657


What is the use of runworkasync() methods?

581


How insert record in the database?

603


Explain the difference between listindex and tab index?

548


Which template creates a .net compact framework 2.0 forms application for pocket pc 2003 and later?

565


What is the extension of the windows installer file?

580


What is the difference between desktop application and windows application?

492