DataReader method of linking database

xiaoxiao2021-03-06  40

/ / Link database (pay attention to service address, user name, password and database source) String connString = "server = Xccn_netdust; uid = sa; pwd = 123456; database = pubs"; sqlconnection mycon = new sqlconnection; connString;

// Database query statement creates sqlcommand mycmd = mycon.createCommand (); mycmd.commandtext = "select au_fname from authors";

// Open the data and bind TRY {MyCon.Open (); SqlDataReader DR = mycmd.executeReader (); // This example will be bound to a DropDownList. Note Bind to DROPDOWNLIST and other display names and values ​​// To pay attention to setting the value of DataTextField and DataValueField two attributes. DropdownList1.datasource = Dr; DROPDOWNLIST1.DATEXTFIELD = "au_fname"; DropDownList1.Database ();} finally {// Turns the database (when the database is bound to turn off the database to save system resources) Mycon.dispose (); }

转载请注明原文地址:https://www.9cbs.com/read-78932.html

New Post(0)