public static List <ViewModel_DropDownGrid> GetTableValues(string TableName) { List <ViewModel_DropDownGrid> list_ViewModel_DropDownGrid = new List <ViewModel_DropDownGrid>(); using (SqlConnection connection = new SqlConnection(strCRMARConnectionString)) { connection.Open(); //string strQuery = // string.Format(@"SELECT ID, DESCRIPTION,ACTIVE // FROM INCIDENT_{0} ", TableName); string strQuery = string.Format(@"SELECT Id, Description,Active from {0} ", TableName); SqlCommand cmd = new SqlCommand(strQuery, connection); SqlDataReader reader = null; reader = cmd.ExecuteReader(); while (reader.Read()) { ViewModel_DropDownGrid viewModel = new ViewModel_DropDownGrid() { TableId = Convert.ToInt32(reader["Id"]), Description = reader["Description"].ToString(), Active = Convert.ToBoolean(reader["Active"]) }; list_ViewModel_DropDownGrid.Add(viewModel); } } return(list_ViewModel_DropDownGrid); }
public static void UpdateTableValues(string TableName, ViewModel_DropDownGrid Griddata) { List <ViewModel_DropDownGrid> list_ViewModel_DropDownGrid = new List <ViewModel_DropDownGrid>(); using (SqlConnection connection = new SqlConnection(strCRMARConnectionString)) { connection.Open(); string strQuery = string.Format(@"INSERT INTO {0} (Description,Active) VALUES(@param_Description,@param_Active)", TableName); SqlCommand cmd = new SqlCommand(strQuery, connection); cmd.Parameters.AddWithValue("@param_Description", Griddata.Description); cmd.Parameters.AddWithValue("@param_Active", Griddata.Active); cmd.CommandType = CommandType.Text; cmd.ExecuteNonQuery(); } }