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

Explain the new events in textbox that has been included in vb?

620


What is difference between winforms and windows forms?

673


Explain the difference between listindex and tab index?

627


Which command prompt utility is used to convert a resource file from the text format into the binary format?

686


Which event occurs when a user drags an item in a treeview or listview control?

635






how print barcode

2192


What is form and its types?

607


What is the advantage of a form?

655


Which property of the progressbar control specifies the amount to increment the current value of the control?

599


What is form description?

614


Explain how to net forms the windows?

655


What is the difference between pixels, points, and em’s when fonts are displayed?

638


Which window displays messages for the status of various features provided in the visual studio .net ide?

636


What is a database form?

567


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

632