Пример #1
0
        private void SearchAmbilKtm() //select dari simak
        {
            SqlConnection conn = null;

            try
            {
                string konekKe  = null;
                string queryUse = null;

                cQuery   qr      = new cQuery();
                cKoneksi koneksi = new cKoneksi();

                if (rbMahasiswa.Checked == true)
                {
                    konekKe  = "2";//2 = ke simak
                    queryUse = qr.qSearchMhsAmbilKtm(nik, nama);
                }
                else
                {
                    konekKe  = "4";//4 = ke payroll
                    queryUse = qr.qSearchAmbilKartuPeg(nik, nama);
                }

                conn = new SqlConnection(koneksi.konekMsSql(Convert.ToChar(konekKe)));
                SqlCommand cmd = null;
                //---------------------------------
                cmd = new SqlCommand(queryUse, conn);
                //---------------------------------
                conn.Open();
                cmd.ExecuteNonQuery();
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataSet        ds = new DataSet();
                da.Fill(ds, "Authors_table");
                //---------------------
                dataGridView1.DataSource = ds;
                dataGridView1.DataMember = "Authors_table";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                conn.Close();
                conn.Dispose();
            }
        }