Metode pembacaan dan pengoperasian data yang sederhana dan praktis, tempelkan ke dalam program dan langsung panggil
metode pembacaan:
Kueri Kumpulan Data publik (string SQLText)
{
SqlConnection myConnection=new SqlConnection(ConfigurationSettings.AppSettings["sambungan"]);
Kumpulan Data ds = Kumpulan Data baru();
SqlDataAdapter myCommand = new SqlDataAdapter(SQLText,myConnection);
myCommand.Isi(ds);
kembali ds;
}
Metode operasi:
//Jalankan query dan kembalikan SqlDataReader
SqlDataReader publik QueryByReader (string sqlstr)
{
if (sqlstr==String.Kosong)
kembalikan nol;
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["connstring"]);
SqlCommand myCommand = new SqlCommand(sqlstr, myConnection)
;
Hasil SqlDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
hasil pengembalian;
}
//Operasikan database dan jangan mengembalikan hasil
bool publik OperateDB(string sqlstr)
{
if (sqlstr==String.Kosong)
return false;
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["connstring"]);
SqlCommand myCommand = new SqlCommand(sqlstr, myConnection)
;
myCommand.ExecuteNonQuery();
myConnection.Close();
mengembalikan nilai true;
}