Untuk mendapatkan data dari tabel data di database:
public DataTable getData()
{
try
{
connect.Open();
SqlCommand com = new SqlCommand();
com.Connection = connect;
com.CommandType = CommandType.Text;
com.CommandText = "select field1, field2, field3 from data";
DataTable ds = new DataTable();
SqlDataAdapter adp = new SqlDataAdapter(com);
adp.Fill(ds);
connect.Close();
return ds;
}
catch (NullReferenceException e)
{
return null;
}
}
Semoga membantu ...^^
Tidak ada komentar:
Posting Komentar