firas shaar

firas shaar

  • NA
  • 15
  • 17.8k

how to fetch all rows inserted in datagridview in c#

Sep 14 2014 12:23 PM
I fetch maxid row to view in datagridview using the following code
 public static DataTable GetMaximpID()
        {
            string strconn = AlShehabi.Properties.Settings.Default.NewSalariesDBConnectionString;
            SqlConnection conn = new SqlConnection(strconn);

            if (conn.State == ConnectionState.Closed)
            {
                conn.Open();
            }
            SqlCommand command = new SqlCommand("select * from Imprests where Imprest_ID= (Select MAX(imprest_ID) FROM Imprests)", conn);

            SqlDataAdapter adpater = new SqlDataAdapter(command);
            DataTable dt = new DataTable();
            try
            {
                adpater.Fill(dt);
            }


            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            conn.Close();
            return dt;
        }
but I want to fetch all rows inserted and view in datagridview
for example if user insert 4 rows I want to view them in datagridview after insert them
using insertbutton_click