Write a program to select records from database and display them in ListBox.//All
Try{
string constring=@"Data Source=C:\anudb1.mdb;"+@"Provider=Microsoft.Jet.OLEDB.4.0";
string mySelectQuery = "Select * from Profile";
OleDbConnection myConnection = new OleDbConnection(constring);
OleDbCommand myCommand = new OleDbCommand(mySelectQuery,myConnection);
myConnection.Open();
OleDbDataReader myReader=null;
myReader = myCommand.ExecuteReader();
while(myReader.Read())
{
listBox1.Items.Add(myReader["Name"]+" , "+myReader["Address"]);
}
myReader.Close();
myConnection.Close();
}catch(){}
Write a program to connect to database using DataAdapter and fill the
DataSet, display content in DataGrid.
string strSql="Select * from Profile";
string constring=@"Data Source=C:\anudb1.mdb;"+@"Provider=Microsoft.Jet.OLEDB.4.0";
OleDbConnection con=new OleDbConnection(constring);
OleDbDataAdapter adap=new OleDbDataAdapter();
adap.SelectCommand=new OleDbCommand(strSql,con);
DataSet ds=new DataSet();
adap.Fill(ds);
this.dataGrid1.DataSource=ds;
No comments:
Post a Comment